Update fzf location
[dotfiles] / .bash_tmux
1 # tmux completion by Fahd Shariff
2
3 _tmux() {
4 # an array of commands and their options
5 declare -A tmux_cmd_map
6 tmux_cmd_map=( ["attach-session"]="-dr -t target-session" \
7 ["bind-key"]="-cnr -t key-table key command arguments" \
8 ["break-pane"]="-d -t target-pane" \
9 ["capture-pane"]="-b buffer-index -E end-line -S start-line -t target-pane" \
10 ["choose-buffer"]="-t target-window template" \
11 ["choose-client"]="-t target-window template" \
12 ["choose-session"]="-t target-window template" \
13 ["choose-window"]="-t target-window template" \
14 ["clear-history"]="-t target-pane" \
15 ["clock-mode"]="-t target-pane" \
16 ["command-prompt"]="-I inputs -p prompts -t target-client template" \
17 ["confirm-before"]="-p prompt -t target-client command" \
18 ["copy-mode"]="-u -t target-pane" \
19 ["delete-buffer"]="-b buffer-index" \
20 ["detach-client"]="-P -s target-session -t target-client" \
21 ["display-message"]="-p -c target-client -t target-pane message" \
22 ["display-panes"]="-t target-client" \
23 ["find-window"]="-t target-window match-string" \
24 ["has-session"]="-t target-session" \
25 ["if-shell"]="shell-command command" \
26 ["join-pane"]="-dhv -p percentage|-l size -s src-pane -t dst-pane" \
27 ["kill-pane"]="-a -t target-pane" \
28 ["kill-server"]="kill-server" \
29 ["kill-session"]="-t target-session" \
30 ["kill-window"]="-t target-window" \
31 ["last-pane"]="-t target-window" \
32 ["last-window"]="-t target-session" \
33 ["link-window"]="-dk -s src-window -t dst-window" \
34 ["list-buffers"]="list-buffers" \
35 ["list-clients"]="-t target-session" \
36 ["list-commands"]="list-commands" \
37 ["list-keys"]="-t key-table" \
38 ["list-panes"]="-as -t target" \
39 ["list-sessions"]="list-sessions" \
40 ["list-windows"]="-a -t target-session" \
41 ["load-buffer"]="-b buffer-index path" \
42 ["lock-client"]="-t target-client" \
43 ["lock-server"]="lock-server" \
44 ["lock-session"]="-t target-session" \
45 ["move-window"]="-dk -s src-window -t dst-window" \
46 ["new-session"]="-d -n window-name -s session-name -t target-session -x width -y height command" \
47 ["new-window"]="-adk -n window-name -t target-window command" \
48 ["next-layout"]="-t target-window" \
49 ["next-window"]="-a -t target-session" \
50 ["paste-buffer"]="-dr -s separator -b buffer-index -t target-pane" \
51 ["pipe-pane"]="-t target-pane-o command" \
52 ["previous-layout"]="-t target-window" \
53 ["previous-window"]="-a -t target-session" \
54 ["refresh-client"]="-t target-client" \
55 ["rename-session"]="-t target-session new-name" \
56 ["rename-window"]="-t target-window new-name" \
57 ["resize-pane"]="-DLRU -t target-pane adjustment" \
58 ["respawn-pane"]="-k -t target-pane command" \
59 ["respawn-window"]="-k -t target-window command" \
60 ["rotate-window"]="-DU -t target-window" \
61 ["run-shell"]="command" \
62 ["save-buffer"]="-a -b buffer-index" \
63 ["select-layout"]="-np -t target-window layout-name" \
64 ["select-pane"]="-lDLRU -t target-pane" \
65 ["select-window"]="-lnp -t target-window" \
66 ["send-keys"]="-t target-pane key " \
67 ["send-prefix"]="-t target-pane" \
68 ["server-info"]="server-info" \
69 ["set-buffer"]="-b buffer-index data" \
70 ["set-environment"]="-gru -t target-session name value" \
71 ["set-option"]="-agsuw -t target-session|target-window option value" \
72 ["set-window-option"]="-agu -t target-window option value" \
73 ["show-buffer"]="-b buffer-index" \
74 ["show-environment"]="-g -t target-session" \
75 ["show-messages"]="-t target-client" \
76 ["show-options"]="-gsw -t target-session|target-window" \
77 ["show-window-options"]="-g -t target-window" \
78 ["source-file"]="path" \
79 ["split-window"]="-dhvP -p percentage|-l size -t target-pane command" \
80 ["start-server"]="start-server" \
81 ["suspend-client"]="-t target-client" \
82 ["swap-pane"]="-dDU -s src-pane -t dst-pane" \
83 ["swap-window"]="-d -s src-window -t dst-window" \
84 ["switch-client"]="-lnp -c target-client -t target-session" \
85 ["unbind-key"]="-acn -t key-table key" \
86 ["unlink-window"]="-k -t target-window" )
87
88 declare -A tmux_alias_map
89 tmux_alias_map=( ["attach"]="attach-session" \
90 ["detach"]="detach-client" \
91 ["has"]="has-session" \
92 ["lsc"]="list-clients" \
93 ["lscm"]="list-commands" \
94 ["ls"]="list-sessions" \
95 ["lockc"]="lock-client" \
96 ["locks"]="lock-session" \
97 ["new"]="new-session" \
98 ["refresh"]="refresh-client" \
99 ["rename"]="rename-session" \
100 ["showmsgs"]="show-messages" \
101 ["source"]="source-file" \
102 ["start"]="start-server" \
103 ["suspendc"]="suspend-client" \
104 ["switchc"]="switch-client" \
105 ["breakp"]="break-pane" \
106 ["capturep"]="target-pane]" \
107 ["displayp"]="display-panes" \
108 ["findw"]="find-window" \
109 ["joinp"]="join-pane" \
110 ["killp"]="kill-pane" \
111 ["killw"]="kill-window" \
112 ["lastp"]="last-pane" \
113 ["last"]="last-window" \
114 ["linkw"]="link-window" \
115 ["lsp"]="list-panes" \
116 ["lsw"]="list-windows" \
117 ["movew"]="move-window" \
118 ["neww"]="new-window" \
119 ["nextl"]="next-layout" \
120 ["next"]="next-window" \
121 ["pipep"]="pipe-pane" \
122 ["prevl"]="previous-layout" \
123 ["prev"]="previous-window" \
124 ["renamew"]="rename-window" \
125 ["resizep"]="resize-pane" \
126 ["respawnp"]="respawn-pane" \
127 ["respawnw"]="respawn-window" \
128 ["rotatew"]="rotate-window" \
129 ["selectl"]="select-layout" \
130 ["selectp"]="select-pane" \
131 ["selectw"]="select-window" \
132 ["splitw"]="[shell-command]" \
133 ["swapp"]="swap-pane" \
134 ["swapw"]="swap-window" \
135 ["unlinkw"]="unlink-window" \
136 ["bind"]="bind-key" \
137 ["lsk"]="list-keys" \
138 ["send"]="send-keys" \
139 ["unbind"]="unbind-key" \
140 ["set"]="set-option" \
141 ["setw"]="set-window-option" \
142 ["show"]="show-options" \
143 ["showw"]="show-window-options" \
144 ["setenv"]="set-environment" \
145 ["showenv"]="show-environment" \
146 ["confirm"]="confirm-before" \
147 ["display"]="display-message" \
148 ["clearhist"]="clear-history" \
149 ["deleteb"]="delete-buffer" \
150 ["lsb"]="list-buffers" \
151 ["loadb"]="load-buffer" \
152 ["pasteb"]="paste-buffer" \
153 ["saveb"]="save-buffer" \
154 ["setb"]="set-buffer" \
155 ["showb"]="show-buffer" \
156 ["if"]="if-shell" \
157 ["lock"]="lock-server" \
158 ["run"]="run-shell" \
159 ["info"]="server-info" )
160
161 local cur="${COMP_WORDS[COMP_CWORD]}"
162 local prev="${COMP_WORDS[COMP_CWORD-1]}"
163 COMPREPLY=()
164
165 # completing an option
166 if [[ "$cur" == -* ]]; then
167 #tmux options
168 if [[ "$prev" == "tmux" ]]; then
169 COMPREPLY=( $( compgen -W "-2 -8 -c -f -L -l -q -S -u -v -V" -- $cur ) )
170 else
171 #find the tmux command so that we can complete the options
172 local cmd="$prev"
173 local i=$COMP_CWORD
174 while [[ "$cmd" == -* ]]
175 do
176 cmd="${COMP_WORDS[i]}"
177 ((i--))
178 done
179
180 #if it is an alias, look up what the alias maps to
181 local alias_cmd=${tmux_alias_map[$cmd]}
182 if [[ -n ${alias_cmd} ]]
183 then
184 cmd=${alias_cmd}
185 fi
186
187 #now work out the options to this command
188 local opts=""
189 for opt in ${tmux_cmd_map[$cmd]}
190 do
191 if [[ "$opt" == -* ]]; then
192 len=${#opt}
193 i=1
194 while [ $i -lt $len ]; do
195 opts="$opts -${opt:$i:1}"
196 ((i++))
197 done
198 fi
199 done
200 COMPREPLY=($(compgen -W "$opts" -- ${cur}))
201 fi
202 else
203 COMPREPLY=($(compgen -W "$(echo ${!tmux_cmd_map[@]} ${!tmux_alias_map[@]})" -- ${cur}))
204 fi
205 return 0
206 }
207 complete -F _tmux tmux