├── README.md ├── tmux-hints-sh.png └── tmux-hints.sh /README.md: -------------------------------------------------------------------------------- 1 | # tmux-hints 2 | Automatically show a cheat sheet or notes for any command focused in tmux. e.i. Show vim, zsh, tmux notes/key-combos in a pane when using them. 3 | 4 | More info the blog post: https://benhoskins.dev/tmux-hints-sh-auto-cheatsheet-for-vim-zsh-tmux/ 5 | 6 | ![tmux-hint.sh Screenshot](https://raw.githubusercontent.com/hozza/tmux-hints/master/tmux-hints-sh.png) 7 | 8 | ## Install 9 | 10 | This is a bash script, you only need bash as a dependency _(which you probably already have)_ and whatever programme you'd like to show the hint file with, default is `cat`. 11 | 12 | ```bash 13 | $ git clone https://github.com/hozza/tmux-hints.git 14 | $ cd tmux-hints/ 15 | $ chmod +x ./tmux-hints.sh 16 | $ ./tmux-hints.sh 17 | ``` 18 | ## Usage 19 | 20 | 1. Make some 'hint files' - notes, cheat-sheets or memos for to show when using various commands and save them in `~/hints/`. 21 | 22 | 2. Run `./tmux-hints.sh` in a tmux pane of your choice. 23 | 24 | 3. Profit. 25 | 26 | When you focus on another pane, running for example, `vim` .. The pane running `tmux-hints.sh` will automatically load your 'hint file' within 1 second, when you focus on something else, such as, `zsh` it'll show your zsh hint file without you having todo anything or pull-up a different notes file. 27 | 28 | **What's a hint file?** I hear you ask, it's a text file of notes you've written and saved in `~/hints/`. 29 | 30 | e.g. You could include key-combo/shortcut/custom-key-mappings of your new VIM/TMUX config, maybe also notes to remind you about some aspects of it's usage. 31 | 32 | **Markdown?** If you have some sort of markdown viewer installed, and have md files as your hints. You can use the following: 33 | 34 | `./tmux-hints.sh -o markdown -x md` 35 | 36 | `-o markdown` specifies the `markdown` viewer/**o**pener you have installed (it uses `cat` by default). 37 | 38 | `-x md` specify the hint file extension. 39 | 40 | Taken some other path? If you have your notes/hints stored somewhere else you can specify a path with: 41 | 42 | `./tmux-hints.sh -p ~/.dotfiles/hints/` 43 | 44 | e.g. you have your hint files stored like so `~/.dotfiles/hints/vim.txt` 45 | 46 | ## Not working? 47 | 48 | Be gentle, this is my first attempt at bash scripting. 49 | 50 | Use the `-v` option to show what it's doing and hopefully where it's going wrong. 51 | 52 | It uses tmux's built in hooks, specifically `pane-focus-in` and the tmux format expansion `#{pane_current_command}`. If you're running a bash script, tmux only returns 'bash' as the command not the script name. So you can't have hint files for specific scripts unfortunately _(just put script specific hints in your `~/hints/bash.txt` hint file and see them all at once)_ 53 | 54 | This does not come with the 'hint files' - as they are notes personal to you and your setup, and so you'll need to write some! e.g. If you have new vim plugins with custom maps that you can't quite remember just yet. 55 | -------------------------------------------------------------------------------- /tmux-hints-sh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hozza/tmux-hints/459e2b4a005ed723eea3e89c6524925eddc40c93/tmux-hints-sh.png -------------------------------------------------------------------------------- /tmux-hints.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # tmux-hints.sh by hozza 4 | # 5 | # In a tmux pane run this script with: 6 | # '$ /path/to/tmux-hints.sh' 7 | # 8 | # Use '$ /path/to/tmux-hints.sh -h' for help/usage. 9 | # 10 | # When you focus (click/move) onto another pane 11 | # it'll show your cheat sheet for that command. 12 | # 13 | # Useful for learning new shortcuts without flicking 14 | # though loads of txt/md notes. 15 | # 16 | 17 | export PATH=/usr/local/bin:/bin:/usr/bin 18 | tag=${0##*/} 19 | 20 | say () { echo "$tag: $@" ; } 21 | die () { say "FATAL: $@" ; exit 1; } 22 | 23 | # sanity check 24 | case "$TMUX" in 25 | "") die "You need to be running tmux to use tmux-hints!" ;; 26 | *) ;; 27 | esac 28 | 29 | 30 | header_init="# $tag\n" 31 | 32 | viewer="cat" 33 | extension=".txt" 34 | hint_path="$HOME/hints/" 35 | verbose=false 36 | quiet=false 37 | repo="https://github.com/hozza/tmux-hints" 38 | version="0.3" 39 | 40 | # help doc 41 | help () { 42 | echo -e "$header_init" 43 | 44 | cat < $temp_file'" 86 | 87 | 88 | clear_term="$(tput clear)" 89 | [ "$verbose" == true ] && clear_term='' 90 | 91 | default="\nCreate a default hint file:\n\n"$hint_path"tmux"$extension"\n\nExit:\tCtrl+c\n\nUpdate:\t'git pull' in tmux-hint directory.\n\nHelp:\ttmux-hints.sh -h\n\nRepo:\t$repo\n" 92 | 93 | # init 94 | if [ "$quiet" == true ]; then 95 | header_init="" 96 | default="" 97 | fi 98 | echo -e $clear_term$header_init 99 | init=true 100 | 101 | 102 | ### Set initial time of file 103 | LTIME=`stat -c %Z $temp_file` 104 | 105 | # loop - checking for changes to tmp file 106 | while true 107 | do 108 | ATIME=`stat -c %Z $temp_file` 109 | 110 | if [ "$ATIME" != "$LTIME" ] || [ "$init" == true ] 111 | then 112 | 113 | this_hint=$( cat $temp_file ) 114 | echo -ne $clear_term 115 | 116 | if [ "$init" == true ]; then this_hint="tmux"; fi 117 | init=false 118 | 119 | # show this hint 120 | header="$header_init" 121 | 122 | # verbose full command 123 | [ "$verbose" == true ] && header=$header"# Exact Command Used: $viewer $hint_path$this_hint$extension\n" 124 | 125 | # hint exists? default hint? 126 | hint_exists=true 127 | if [ ! -f "$hint_path$this_hint$extension" ]; then 128 | 129 | # defaults? 130 | if [ -f $hint_path"tmux"$extension ]; then 131 | header=$header"# $this_hint hint not found.\n" 132 | this_hint="tmux" 133 | else 134 | header=$header"# tmux hint not found.\n"$default 135 | hint_exists=false; 136 | fi 137 | 138 | fi 139 | 140 | # output! 141 | if [ "$quiet" == false ]; then 142 | echo -e "$header# $this_hint$extension\n" 143 | fi 144 | 145 | if [ "$hint_exists" == true ]; then 146 | echo -e "$( $viewer $hint_path$this_hint$extension )" 147 | fi 148 | 149 | LTIME=$ATIME 150 | 151 | fi 152 | sleep 1 153 | done 154 | 155 | 156 | --------------------------------------------------------------------------------