fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Jian Weihangcompletions/tmux: complete directories for new-session -cb2c23eb39

master
32.3 KiB636 linesraw
1function __fish_tmux_sessions -d 'available sessions'
2    tmux list-sessions -F "#S"\t"#{session_windows} windows created: #{session_created_string} [#{session_width}x#{session_height}]#{session_attached}" | sed 's/0$//;s/1$/ (attached)/' 2>/dev/null
3end
4
5function __fish_tmux_clients -d 'connected clients'
6    tmux list-clients -F "#{client_tty}"\t"#S: Created: #{client_created_string} [#{client_width}x#{client_height} #{client_termname}]" 2>/dev/null
7end
8
9# These are meant to be used with `complete --keep-order`
10function __fish_tmux_panes -d "list tmux panes in the current session"
11    set -l pane_details_format (
12        string join '' \
13        '[#W] #{=/15/...:pane_title}' \
14        '#{?pane_marked, <marked>,}' \
15        '#{?window_active, <active #{?pane_active,pane,win.}>,}'
16        # TODO: Could show <zoomed>/<invisible> for active/inactive panes in a zoomed window
17    )
18    # panes by themselves (current window)
19    # For pane commands, `tmux` understands an integer to mean "pane
20    # with this index in the current window"
21    tmux list-panes -F "#P"\t"#D $pane_details_format" 2>/dev/null
22
23    # window.pane index
24    tmux list-panes -s -F "#I.#P"\t"#D $pane_details_format" 2>/dev/null
25
26    # unique pane id
27    # These ids start with `%` and do not change when panes are reordered,
28    # nor when they are moved to another window or session. We show them
29    # for context in above completions, and support completing them.
30    tmux list-panes -s -F "#D"\t"#I.#P $pane_details_format" | sort -n -k 1.2 2>/dev/null
31
32    # We could also add the panes in the `session:window.pane` syntax,
33    # but there's not reason to use it in the common case where the
34    # person is interested in the current tmux session (or there is only
35    # one tmux session). This can also be confusing when "sesssion groups"
36    # are used
37end
38
39function __fish_tmux_buffers -d buffers
40    tmux list-buffers -F '#{buffer_name}'\t'#{buffer_sample}' 2>/dev/null
41end
42
43# Meant to be used with `complete --keep-order`, since tmux follows numerical order
44function __fish_tmux_windows -d "list tmux windows in the current session"
45    # Using the same notation as tmux's default status bar. Could use <marked>, <active>, etc.
46    # Unlike tmux's statusbar , we add a space for readability
47    set -l window_flags '#{?window_active, *,}#{?window_marked_flag, M,}#{?window_zoomed_flag, Z,}'
48
49    # In window context, an integer means a window index in this session
50    tmux list-windows -F "#I"\t"#W$window_flags" 2>/dev/null
51
52    # Showing windows in other sessions can be confusing e.g. if there
53    # are session groups. So, we assume the user is interested in the
54    # current (or only) session.
55end
56
57#don't allow dirs in the completion list...
58complete -c tmux -x
59
60###############  Begin: Dynamic Completions Using `tmux list-commands` ###############
61
62# The dynamic completions are exhaustive. The manual completions below override
63# them with better-documented completions and custom completions for some
64# arguments, e.g. for target panes, but only have partial coverage.
65function __fish_tmux_parse_lscm_usage
66    set -l lscm (tmux list-commands -F "#{command_list_name} #{command_list_alias}"\t"#{command_list_usage}" 2>/dev/null)
67    or return
68
69    for cmd_tab_usage in $lscm
70        set -l split_command (string split --max 2 \t -- $cmd_tab_usage)
71        set -l cmdnames $split_command[1]
72        set -l usage $split_command[2]
73
74        complete -c tmux -n __fish_use_subcommand -a "$cmdnames"
75
76        # $usage has the form '[-ABCD] [-L|-S|-U] [-e arg-name] [positional-arg-name]'
77        for item in (string match -ag --regex '\[([^\]]+)\]' $usage)
78            if not set -l item (string trim -l -c - -- $item)
79                continue
80            end
81            if set -l split_item (string split -n --max 2 " " -- "$item")
82                # The option should always have length 1 by tmux convention,
83                # but we double-check to avoid syntax errors.
84                if [ "$(string length $split_item[1])" = 1 ]
85                    complete -c tmux -xs $split_item[1] -n "__fish_seen_subcommand_from $cmdnames" -d "$split_item[2]"
86                end
87            else
88                for char in (string split '' -- "$item")
89                    if string match -q -r '\||-' -- $char
90                        # TODO: Actually treat exclusive args, [-L|-S|-U], as exclusive
91                        # For now, we just ignore the `-`s and `|`s
92                        continue
93                    end
94                    complete -c tmux -n "__fish_seen_subcommand_from $cmdnames" -s $char
95                end
96            end
97        end
98    end
99end
100
101__fish_tmux_parse_lscm_usage
102functions -e __fish_tmux_parse_lscm_usage
103
104# Completions for `tmux list-commands` itself
105set -l all_commands (tmux list-commands -F "#{command_list_name} #{command_list_alias}" 2>/dev/null)
106and complete -c tmux -n "__fish_seen_subcommand_from list-commands lscm" -x -a "$all_commands"
107
108###############  End:   Dynamic Completions Using `tmux list-commands` ###############
109
110###############  Begin: Front  Flags ###############
111#these do not require parameters
112complete -c tmux -n __fish_use_subcommand -s 2 -d 'Force tmux to assume the terminal supports 256 colours'
113complete -c tmux -n __fish_use_subcommand -s 8 -d 'Like -2, but indicates that the terminal supports 88 colours'
114complete -c tmux -n __fish_use_subcommand -s l -d 'Behave as a login shell'
115complete -c tmux -n __fish_use_subcommand -s q -d 'Set the quiet server option'
116complete -c tmux -n __fish_use_subcommand -s u -d 'Flag explicitly informs tmux that UTF-8 is supported'
117complete -c tmux -n __fish_use_subcommand -s v -d 'Request verbose logging'
118complete -c tmux -n __fish_use_subcommand -s V -d 'Report the tmux version'
119
120#these require parameters
121complete -c tmux -n __fish_use_subcommand -xs c -d 'Execute command using the default shell'
122complete -c tmux -n __fish_use_subcommand -rs f -d 'Alternate config file'
123complete -c tmux -n __fish_use_subcommand -rs L -d 'Specify the name of the server socket to use'
124complete -c tmux -n __fish_use_subcommand -rs S -d 'Full path to server socket. If set, -L is ignored.'
125###############  End:   Front  Flags ###############
126
127###############  Begin: Clients and Sessions ###############
128set -l attach 'attach-session attach at a'
129set -l detach 'detach-client detach'
130set -l has 'has-session has'
131set -l killserver kill-server
132set -l killsession kill-session
133set -l lsc 'list-clients lsc'
134set -l lscm 'list-commands lscm'
135set -l ls 'list-sessions ls'
136set -l lockc 'lock-client lockc'
137set -l locks 'lock-session locks'
138set -l new 'new-session new'
139set -l refresh 'refresh-client refresh'
140set -l rename 'rename-session rename'
141set -l showmsgs 'show-messages showmsgs'
142set -l source 'source-file source'
143set -l start 'start-server start'
144set -l suspendc 'suspend-client suspendc'
145set -l switchc 'switch-client switchc'
146
147complete -c tmux -n __fish_use_subcommand -a $attach -d 'attach to existing session'
148complete -c tmux -n "__fish_seen_subcommand_from $attach" -s d -d 'detach other clients'
149complete -c tmux -n "__fish_seen_subcommand_from $attach" -s r -d 'attach in read-only mode'
150
151complete -c tmux -n __fish_use_subcommand -a $detach -d 'detach current client'
152complete -c tmux -n "__fish_seen_subcommand_from $detach" -s P -d 'SIGHUP parent process of client, likely causing it to exit'
153
154complete -c tmux -n __fish_use_subcommand -a $has -d 'report error and exit with 1 if the session does not exist'
155complete -c tmux -n __fish_use_subcommand -a $killserver -d 'kill tmux server, clients, and sessions'
156complete -c tmux -n __fish_use_subcommand -a $killsession -d 'destroy session, close its windows, and detach all its clients'
157complete -c tmux -n __fish_use_subcommand -a $lsc -d 'list all attached clients'
158complete -c tmux -n __fish_use_subcommand -a $lscm -d 'list syntax for all tmux commands'
159complete -c tmux -n __fish_use_subcommand -a $ls -d 'list all sessions'
160complete -c tmux -n __fish_use_subcommand -a $lockc -d 'lock client'
161complete -c tmux -n __fish_use_subcommand -a $locks -d 'lock session'
162
163complete -c tmux -n __fish_use_subcommand -a $new -d 'create a new session with name session-name'
164complete -c tmux -n "__fish_seen_subcommand_from $new" -s d -d "don't attach to current window"
165complete -c tmux -n "__fish_seen_subcommand_from $new" -s A -d "attach to existing session if session-name already exists"
166complete -c tmux -n "__fish_seen_subcommand_from $new" -s D -d "if -A is specified, detach other clients attached to the session"
167complete -c tmux -n "__fish_seen_subcommand_from $new" -s P -d "print information about the new session after creation"
168complete -c tmux -n "__fish_seen_subcommand_from $new" -s E -d "don't apply update-environment option"
169complete -c tmux -n "__fish_seen_subcommand_from $new" -xs c -d start-directory -a "(__fish_complete_directories)"
170complete -c tmux -n "__fish_seen_subcommand_from $new" -xs F -d format
171complete -c tmux -n "__fish_seen_subcommand_from $new" -xs n -d window-name
172complete -c tmux -n "__fish_seen_subcommand_from $new" -xs s -d session-name
173complete -c tmux -n "__fish_seen_subcommand_from $new" -xs t -d group-name
174complete -c tmux -n "__fish_seen_subcommand_from $new" -xs x -d width
175complete -c tmux -n "__fish_seen_subcommand_from $new" -xs y -d height
176
177complete -c tmux -n __fish_use_subcommand -a $refresh -d 'refresh client'
178complete -c tmux -n "__fish_seen_subcommand_from $refresh" -s S -d 'update client status bar'
179
180complete -c tmux -n __fish_use_subcommand -a $rename -d 'rename session'
181complete -c tmux -n __fish_use_subcommand -a $showmsgs -d 'save msgs in status bar in per-client msg log'
182
183complete -c tmux -n __fish_use_subcommand -a $source -d 'execute commands from path'
184complete -c tmux -n "__fish_seen_subcommand_from $source" -F
185
186complete -c tmux -n __fish_use_subcommand -a $start -d 'start tmux server if not running; do not create a session'
187
188complete -c tmux -n __fish_use_subcommand -a $suspendc -d 'send SIGTSTP signal to client (tty stop)'
189
190complete -c tmux -n __fish_use_subcommand -a $switchc -d 'Switch the current session for client target-client to target-session'
191complete -c tmux -n "__fish_seen_subcommand_from $switchc" -s l -d 'move client to the last session'
192complete -c tmux -n "__fish_seen_subcommand_from $switchc" -s n -d 'move client to the next session'
193complete -c tmux -n "__fish_seen_subcommand_from $switchc" -s p -d 'move client to the previous session'
194complete -c tmux -n "__fish_seen_subcommand_from $switchc" -s r -d 'toggle if client is read-only'
195
196#commands with a session flag
197complete -c tmux -xs t -n "__fish_seen_subcommand_from $attach $new $has $killsession $lsc $locks $rename $switchc" -a '(__fish_tmux_sessions)' -d target-session
198complete -c tmux -xs s -n "__fish_seen_subcommand_from $detach" -a '(__fish_tmux_sessions)' -d target-session
199
200#commands with a client flag
201complete -c tmux -xs t -n "__fish_seen_subcommand_from $detach $lockc $refresh $showmsgs $suspendc" -a '(__fish_tmux_clients)' -d target-client
202complete -c tmux -xs c -n "__fish_seen_subcommand_from $switchc" -a '(__fish_tmux_clients)' -d target-client
203
204#commands with the -F format flag
205complete -c tmux -n "__fish_seen_subcommand_from $lsc $ls" -xs F -d 'format string'
206
207#commands that take shell commands
208complete -c tmux -x -n "__fish_seen_subcommand_from $new " -a '(__fish_complete_subcommand --fcs-skip=2)'
209
210###############  End: Clients and Sessions ###############
211
212###############  Begin: Windows and Panes ###############
213
214set -l breakp "break-pane breakp"
215set -l capturep "capture-pane capturep"
216set -l chooseclient choose-client
217set -l choosetree choose-tree
218set -l customizemode customize-mode
219set -l displayp "display-panes displayp"
220set -l findw "find-window findw"
221set -l joinp "join-pane joinp move-pane movep"
222set -l killp "kill-pane killp"
223set -l killw "kill-window killw"
224set -l lastp "last-pane lastp"
225set -l lastw "last-window lastw"
226set -l linkw "link-window linkw"
227set -l lsp "list-panes lsp"
228set -l lsw "list-windows lsw"
229set -l movew "move-window movew"
230set -l neww "new-window neww"
231set -l nextl "next-layout nextl"
232set -l next "next-window next"
233set -l pipep "pipe-pane pipep"
234set -l prevl "previous-layout prevl"
235set -l prev "previous-window prev"
236set -l renamew "rename-window renamew"
237set -l resizep "resize-pane resizep"
238set -l resizew "resize-window resizew"
239set -l respawnp "respawn-pane respawnp"
240set -l respawnw "respawn-window respawnw"
241set -l rotatew "rotate-window rotatew"
242set -l selectl "select-layout selectl"
243set -l selectp "select-pane selectp"
244set -l selectw "select-window selectw"
245set -l splitw "split-window splitw"
246set -l swapp "swap-pane swapp"
247set -l swapw "swap-window swapw"
248set -l unlinkw "unlink-window unlinkw"
249
250complete -c tmux -n __fish_use_subcommand -a $breakp -d 'break pane off into a new window'
251
252complete -c tmux -n __fish_use_subcommand -a $capturep -d 'capture contents of a pane into a buffer'
253complete -c tmux -n "__fish_seen_subcommand_from $capturep" -xs a -d 'capture alternate screen'
254complete -c tmux -n "__fish_seen_subcommand_from $capturep" -xs p -d 'output to stdout'
255complete -c tmux -n "__fish_seen_subcommand_from $capturep" -xs e -d 'include color escapes'
256complete -c tmux -n "__fish_seen_subcommand_from $capturep" -xs C -d 'escape non-printable chars'
257
258complete -c tmux -n __fish_use_subcommand -a $chooseclient -d 'interactively choose client'
259complete -c tmux -n __fish_use_subcommand -a $choosetree -d 'interactively choose session/window/pane'
260complete -c tmux -n __fish_use_subcommand -a $customizemode -d 'interactively customize settings'
261complete -c tmux -n __fish_use_subcommand -a $displayp -d 'display a visible indicator for each pane'
262complete -c tmux -n __fish_use_subcommand -a $findw -d 'interactively choose window matching pattern'
263
264complete -c tmux -n __fish_use_subcommand -a $joinp -d 'split destination pane and move source pane into one of the halves'
265# $joinp takes a subset of $splitw arguments
266complete -c tmux -n "__fish_seen_subcommand_from $joinp $splitw" -xs b -d 'before target'
267complete -c tmux -n "__fish_seen_subcommand_from $joinp $splitw" -xs h -d horizontal
268complete -c tmux -n "__fish_seen_subcommand_from $joinp $splitw" -xs v -d vertical
269complete -c tmux -n "__fish_seen_subcommand_from $joinp $splitw" -xs l -d 'size in lines/cols'
270complete -c tmux -n "__fish_seen_subcommand_from $joinp $splitw" -xs f -d 'full height/width'
271
272complete -c tmux -n __fish_use_subcommand -a $killp -d 'destroy a pane'
273complete -c tmux -n __fish_use_subcommand -a $killw -d 'destroy a window'
274complete -c tmux -n __fish_use_subcommand -a $lastp -d 'select the previously selected pane'
275complete -c tmux -n __fish_use_subcommand -a $lastw -d 'select the previously selected window'
276complete -c tmux -n __fish_use_subcommand -a $linkw -d 'link source window to destination window'
277
278complete -c tmux -n __fish_use_subcommand -a $lsp -d 'list panes'
279complete -c tmux -n "__fish_seen_subcommand_from $lsp" -xs s -d 'all in session'
280
281complete -c tmux -n __fish_use_subcommand -a $lsw -d 'list windows'
282complete -c tmux -n __fish_use_subcommand -a $movew -d 'move window'
283
284complete -c tmux -n __fish_use_subcommand -a $neww -d 'create a new window'
285complete -c tmux -n "__fish_seen_subcommand_from $neww" -xs k -d 'replace if exists'
286complete -c tmux -n "__fish_seen_subcommand_from $neww" -xs S -d 'select if exists'
287
288complete -c tmux -n __fish_use_subcommand -a $nextl -d 'rearrange panes in a window according to the next layout'
289complete -c tmux -n __fish_use_subcommand -a $next -d 'move to the next window in the session'
290complete -c tmux -n __fish_use_subcommand -a $pipep -d 'pipe output from pane to a shell command'
291complete -c tmux -n __fish_use_subcommand -a $prevl -d 'rearrange panes in a window according to the previous layout'
292complete -c tmux -n __fish_use_subcommand -a $prev -d 'move to the previous window in the session'
293complete -c tmux -n __fish_use_subcommand -a $renamew -d 'rename a window'
294
295complete -c tmux -n __fish_use_subcommand -a $resizep -d 'resize a pane'
296complete -c tmux -n "__fish_seen_subcommand_from $resizep" -xs M -d 'begin mouse resize'
297complete -c tmux -n "__fish_seen_subcommand_from $resizep" -xs T -d 'trim below cursor'
298
299complete -c tmux -n __fish_use_subcommand -a $resizew -d 'resize a window'
300complete -c tmux -n __fish_use_subcommand -a $respawnp -d 'reactivate a pane where a command exited'
301complete -c tmux -n __fish_use_subcommand -a $respawnw -d 'reactivate a window where a command exited'
302complete -c tmux -n __fish_use_subcommand -a $rotatew -d 'rotate panes within a window'
303
304complete -c tmux -n __fish_use_subcommand -a $selectl -d 'rearrange panes according to a given layout'
305set -l layouts 'even-horizontal even-vertical main-horizontal main-horizontal-mirrored main-vertical main-vertical-mirrored tiled'
306complete -c tmux -n "__fish_seen_subcommand_from $selectl" -x -a "$layouts" -d 'predefined layout'
307
308complete -c tmux -n __fish_use_subcommand -a $selectp -d 'activate specific pane'
309complete -c tmux -n "__fish_seen_subcommand_from $selectp" -xs d -d 'disable input'
310complete -c tmux -n "__fish_seen_subcommand_from $selectp" -xs e -d 'enable input'
311complete -c tmux -n "__fish_seen_subcommand_from $selectp" -xs l -d 'previously selected'
312complete -c tmux -n "__fish_seen_subcommand_from $selectp" -xs m -d mark
313complete -c tmux -n "__fish_seen_subcommand_from $selectp" -xs M -d unmark
314
315complete -c tmux -n __fish_use_subcommand -a $selectw -d 'activate specific window'
316complete -c tmux -n "__fish_seen_subcommand_from $selectw" -xs l -d 'previously selected'
317complete -c tmux -n "__fish_seen_subcommand_from $selectw" -xs p -d previous
318complete -c tmux -n "__fish_seen_subcommand_from $selectw" -xs n -d next
319
320complete -c tmux -n __fish_use_subcommand -a $splitw -d 'create a new pane by splitting target-pane'
321# See also $joinp's arguments
322complete -c tmux -n "__fish_seen_subcommand_from $splitw" -xs I -d 'show stdin contents'
323
324complete -c tmux -n __fish_use_subcommand -a $swapp -d 'swap two panes'
325complete -c tmux -n __fish_use_subcommand -a $swapw -d 'swap two windows'
326complete -c tmux -n __fish_use_subcommand -a $unlinkw -d 'unlink target-window'
327
328## commands with pane flag
329complete -c tmux -n "__fish_seen_subcommand_from $breakp $joinp $swapp" -xs s --keep-order -a '(__fish_tmux_panes)' -d 'source pane'
330complete -c tmux -n "__fish_seen_subcommand_from $capturep $chooseclient $choosetree $customizemode $findw" -xs t --keep-order -a '(__fish_tmux_panes)' -d 'target pane'
331complete -c tmux -n "__fish_seen_subcommand_from $killp $pipep $resizep $respawnp $selectl $selectp $splitw" -xs t --keep-order -a '(__fish_tmux_panes)' -d 'target pane'
332# Unclear if there's a meaningful difference between "target pane" and "destination pane", but tmux makes the distinction
333complete -c tmux -n "__fish_seen_subcommand_from $joinp $swapp" -xs t --keep-order -a '(__fish_tmux_panes)' -d 'destination pane'
334
335## commands with window flag
336complete -c tmux -n "__fish_seen_subcommand_from $linkw $movew $swapw" \
337    --keep-order -a '(__fish_tmux_windows)' -xs s -d 'source window'
338complete -c tmux -n "__fish_seen_subcommand_from $breakp $linkw $movew $neww $swapw" \
339    --keep-order -a '(__fish_tmux_windows)' -xs t -d 'destination window'
340complete -c tmux -n "__fish_seen_subcommand_from $killw $lastp $nextl $prevl $renamew" \
341    --keep-order -a '(__fish_tmux_windows)' -xs t -d 'target window'
342complete -c tmux -n "__fish_seen_subcommand_from $resizew $reswpawnw $rotatew $selectw $unlinkw" \
343    --keep-order -a '(__fish_tmux_windows)' -xs t -d 'target window'
344
345## commands with session flag
346complete -c tmux -n "__fish_seen_subcommand_from $lastw $lsw $next $prev" -xs t -a '(__fish_tmux_sessions)' -d 'target session'
347
348## commands with the -F format flag
349complete -c tmux -n "__fish_seen_subcommand_from $breakp $lsp $lsw $neww $chooseclient $choosetree" -xs F -d 'format string'
350
351## commands with -s/-t flags that are not panes/sessions/windows  (nice completion not yet implemented)
352complete -c tmux -n "__fish_seen_subcommand_from $displayp" -xs t -d 'target client'
353complete -c tmux -n "__fish_seen_subcommand_from $lsp" -xs t -d target
354
355#commands that take shell commands
356complete -c tmux -x -n "__fish_seen_subcommand_from $neww $pipep $respawnp $respawnw $splitw" \
357    -a '(__fish_complete_subcommand --fcs-skip=2)'
358
359# Common boolean flags. TODO: -P for "print info", -Z for "zoom"
360complete -c tmux -n "__fish_seen_subcommand_from $breakp $joinp $linkw $neww $movew $splitw $swapp $swapp" -xs d -d 'do not activate'
361
362set -l updownleftright "$resizep $resizew $selectp "
363complete -c tmux -n "__fish_seen_subcommand_from $updownleftright" -xs D -d down
364complete -c tmux -n "__fish_seen_subcommand_from $updownleftright" -xs U -d up
365complete -c tmux -n "__fish_seen_subcommand_from $updownleftright" -xs L -d left
366complete -c tmux -n "__fish_seen_subcommand_from $updownleftright" -xs R -d right
367
368set -l before_after "$breakp $linkw $movew $neww "
369complete -c tmux -n "__fish_seen_subcommand_from $before_after" -xs a -d after
370complete -c tmux -n "__fish_seen_subcommand_from $before_after" -xs b -d before
371
372# Boolean flags, ct'd. Unclear why these are not -a/-b for after/before
373set -l updownnextprev "$rotatew $swapp "
374complete -c tmux -n "__fish_seen_subcommand_from $updownnextprev" -xs D -d down/next
375complete -c tmux -n "__fish_seen_subcommand_from $updownnextprev" -xs U -d up/prev
376
377# Boolean flags, ct'd. When `-a` does not mean "after"
378complete -c tmux -n "__fish_seen_subcommand_from $lsp $lsw" -xs a -d 'all on this server'
379complete -c tmux -n "__fish_seen_subcommand_from $killp $killw" -xs a -d 'all except chosen'
380complete -c tmux -n "__fish_seen_subcommand_from $prev $next" -xs a -d 'with alert'
381
382###############  End:   Windows and Panes ###############
383
384###############  Begin: Key Bindings ###############
385set -l bind 'bind-key bind'
386set -l lsk 'list-keys lsk'
387set -l send 'send-keys send'
388set -l sendprefix send-prefix
389set -l unbind 'unbind-key unbind'
390
391complete -c tmux -n __fish_use_subcommand -a $bind -d 'bind key to command'
392complete -c tmux -n "__fish_seen_subcommand_from $bind" -s c -d 'bind for command mode instead of normal mode'
393complete -c tmux -n "__fish_seen_subcommand_from $bind" -s n -d 'make the binding work without using a prefix key'
394complete -c tmux -n "__fish_seen_subcommand_from $bind" -s r -d 'key may repeat'
395
396complete -c tmux -n __fish_use_subcommand -a $lsk -d 'list all key bindings'
397
398complete -c tmux -n __fish_use_subcommand -a $send -d 'send key or event'
399complete -c tmux -n "__fish_seen_subcommand_from $send" -s R -d 'reset terminal state'
400# TODO: Could list all possible copy mode commands
401complete -c tmux -n "__fish_seen_subcommand_from $send" -s X -d 'copy mode command'
402complete -c tmux -n "__fish_seen_subcommand_from $send" -s l -d 'literal chars'
403complete -c tmux -n "__fish_seen_subcommand_from $send" -s H -d 'hex-encoded chars'
404complete -c tmux -n "__fish_seen_subcommand_from $send" -xs t --keep-order -a '(__fish_tmux_panes)' -d 'target pane'
405
406complete -c tmux -n __fish_use_subcommand -a $sendprefix -d 'send the prefix key'
407complete -c tmux -n "__fish_seen_subcommand_from $sendprefix" -s 2 -d 'use secondary prefix'
408complete -c tmux -n "__fish_seen_subcommand_from $sendprefix" -xs t --keep-order -a '(__fish_tmux_panes)' -d 'target pane'
409
410complete -c tmux -n __fish_use_subcommand -a $unbind -d 'unbind the command bound to key'
411complete -c tmux -n "__fish_seen_subcommand_from $unbind" -s a -d 'remove all key bindings'
412complete -c tmux -n "__fish_seen_subcommand_from $unbind" -s c -d 'binding for command mode'
413complete -c tmux -n "__fish_seen_subcommand_from $unbind" -s n -d 'command bound to key without a prefix (if any) removed'
414
415# key table commands
416# TODO: Could parse output of `tmux lsk` to get a dynamic list that includes any user key tables
417set -l key_table 'copy-mode copy-mode-vi prefix root'
418complete -c tmux -n "__fish_seen_subcommand_from $bind $unbind $lsk" -xs T -d 'key table' -xa "$key_table"
419complete -c tmux -n "__fish_seen_subcommand_from $switchc" -xs T -d 'switch client key table' -xa "$key_table"
420
421###############  End:   Key Bindings ###############
422
423###############  Begin: Options ###############
424set -l setoption 'set set-option'
425set -l showoptions show-options
426set -l options \
427    backspace \
428    buffer-limit \
429    command-alias \
430    default-terminal \
431    copy-command \
432    escape-time \
433    editor \
434    exit-empty \
435    exit-unattached \
436    extended-keys \
437    focus-events \
438    history-file \
439    message-limit \
440    prompt-history-limit \
441    set-clipboard \
442    terminal-features \
443    terminal-overrides \
444    user-keys \
445    activity-action \
446    assume-paste-time \
447    base-index \
448    bell-action \
449    default-command \
450    default-shell \
451    default-size \
452    destroy-unattached \
453    detach-on-destroy \
454    display-panes-active-colour \
455    display-panes-colour \
456    display-panes-time \
457    display-time \
458    history-limit \
459    key-table \
460    lock-after-time \
461    lock-command \
462    message-command-style \
463    message-style \
464    mouse \
465    prefix \
466    renumber-windows \
467    repeat-time \
468    set-titles \
469    set-titles-string \
470    silence-action \
471    status \
472    status-format \
473    status-interval \
474    status-justify \
475    status-keys \
476    status-left \
477    status-left-length \
478    status-left-style \
479    status-position \
480    status-right \
481    status-right-length \
482    status-right-style \
483    status-style \
484    update-environment \
485    visual-activity \
486    visual-bell \
487    visual-silence \
488    word-separators \
489    aggressive-resize \
490    automatic-rename \
491    automatic-rename-format \
492    clock-mode-colour \
493    clock-mode-style \
494    fill-character \
495    main-pane-height \
496    main-pane-width \
497    copy-mode-match-style \
498    copy-mode-mark-style \
499    copy-mode-current-match-style \
500    mode-keys \
501    mode-style \
502    monitor-activity \
503    monitor-bell \
504    monitor-silence \
505    other-pane-height \
506    other-pane-width \
507    pane-active-border-style \
508    pane-base-index \
509    pane-border-format \
510    pane-border-indicators \
511    pane-border-lines \
512    pane-border-status \
513    pane-border-style \
514    popup-style \
515    popup-border-style \
516    popup-border-lines \
517    window-status-activity-style \
518    window-status-bell-style \
519    window-status-current-format \
520    window-status-current-style \
521    window-status-format \
522    window-status-last-style \
523    window-status-separator \
524    window-status-style \
525    window-size \
526    wrap-search \
527    allow-passthrough \
528    allow-rename \
529    alternate-screen \
530    cursor-colour \
531    pane-colours \
532    cursor-style \
533    remain-on-exit \
534    remain-on-exit-format \
535    scroll-on-clear \
536    synchronize-panes \
537    window-active-style \
538    window-style
539complete -c tmux -n __fish_use_subcommand -a "$setoption" -d 'Set or unset option'
540complete -c tmux -n __fish_use_subcommand -a "$showoptions" -d 'Show set options'
541complete -c tmux -n "__fish_seen_subcommand_from $setoption $showoptions" -s p -d 'Pane option'
542complete -c tmux -n "__fish_seen_subcommand_from $setoption $showoptions" -s w -d 'Window option'
543complete -c tmux -n "__fish_seen_subcommand_from $setoption $showoptions" -s s -d 'Server option'
544complete -c tmux -n "__fish_seen_subcommand_from $setoption $showoptions" -s g -d 'Global option'
545complete -c tmux -n "__fish_seen_subcommand_from $setoption" -s F -d 'Expand format'
546complete -c tmux -n "__fish_seen_subcommand_from $setoption" -s u -d 'Unset option'
547complete -c tmux -n "__fish_seen_subcommand_from $setoption" -s U -d 'Unset option, also in child panes'
548complete -c tmux -n "__fish_seen_subcommand_from $setoption" -s o -d 'Prevent override'
549complete -c tmux -n "__fish_seen_subcommand_from $setoption" -s q -d 'Suppress ambiguous option errors'
550complete -c tmux -n "__fish_seen_subcommand_from $setoption" -s a -d Append
551complete -c tmux -n "__fish_seen_subcommand_from $setoption $showoptions" -s t -x -d 'Target pane' --keep-order -a '(__fish_tmux_panes)'
552complete -c tmux -n "__fish_seen_subcommand_from $showoptions" -s q -d 'No error if unset'
553complete -c tmux -n "__fish_seen_subcommand_from $showoptions" -s v -d 'Only show value'
554complete -c tmux -n "__fish_seen_subcommand_from $showoptions" -s H -d 'Include hooks'
555complete -c tmux -n "__fish_seen_subcommand_from $showoptions" -s A -d 'Include inherited options'
556complete -c tmux -n "__fish_seen_subcommand_from $setoption $showoptions; and not __fish_seen_subcommand_from $options" -a "$options"
557
558###############  End:   Options ###############
559
560###############  Begin: Environment ###############
561set -l setenv 'set-environment setenv'
562set -l showenv 'show-environment showenv'
563
564complete -c tmux -n __fish_use_subcommand -a $setenv -d 'Set or unset an environment variable'
565complete -c tmux -n "__fish_seen_subcommand_from $setenv" -s g -d 'global environment'
566complete -c tmux -n "__fish_seen_subcommand_from $setenv" -s r -d 'remove from environment before starting a new process'
567complete -c tmux -n "__fish_seen_subcommand_from $setenv" -s u -d 'unset variable'
568complete -c tmux -xs t -n "__fish_seen_subcommand_from $setenv" -a '(__fish_tmux_sessions)' -d target-session
569
570complete -c tmux -n __fish_use_subcommand -a $showenv -d 'bind key to command'
571complete -c tmux -n "__fish_seen_subcommand_from $showenv" -s g -d 'global environment'
572complete -c tmux -xs t -n "__fish_seen_subcommand_from $showenv" -a '(__fish_tmux_sessions)' -d target-session
573
574###############  End:   Environment ###############
575
576###############  Begin: Status Line ###############
577set -l commandprompt command-prompt
578set -l display 'display-message display'
579
580complete -c tmux -n __fish_use_subcommand -a $commandprompt -d 'Open the command prompt in a client'
581complete -c tmux -n "__fish_seen_subcommand_from $commandprompt" -s I -x -d 'Comma-separated list of initial text for each prompt'
582complete -c tmux -n "__fish_seen_subcommand_from $commandprompt" -s p -x -d 'Comma-separated list of prompts'
583complete -c tmux -n "__fish_seen_subcommand_from $commandprompt" -s t -xa '(__fish_tmux_clients)' -d target-client
584
585complete -c tmux -n __fish_use_subcommand -a $display -d 'Display a message'
586complete -c tmux -n "__fish_seen_subcommand_from $display" -s p -d 'print to stdout'
587complete -c tmux -n "__fish_seen_subcommand_from $display" -s t --keep-order -xa '(__fish_tmux_panes)' -d target-pane
588complete -c tmux -n "__fish_seen_subcommand_from $display" -s c -xa '(__fish_tmux_clients)' -d target-client
589
590###############  End:   Status Line ###############
591
592###############  Begin: Buffers ###############
593
594set -l choosebuffer choose-buffer
595set -l clearhist "clearhist clear-history"
596set -l deleteb "deleteb delete-buffer"
597set -l lsb "lsb list-buffers"
598set -l loadb "loadb load-buffer"
599set -l pasteb "pasteb paste-buffer"
600set -l saveb "saveb save-buffer"
601set -l setb "setb set-buffer"
602set -l showb "showb show-buffer"
603
604complete -c tmux -n __fish_use_subcommand -a $choosebuffer -d 'interactively choose buffer'
605complete -c tmux -n __fish_use_subcommand -a $clearhist -d 'forget history for a pane'
606complete -c tmux -n __fish_use_subcommand -a $deleteb -d 'delete buffer'
607complete -c tmux -n __fish_use_subcommand -a $lsb -d 'list buffers'
608complete -c tmux -n __fish_use_subcommand -a $loadb -d 'load buffer from path, use - for stdin'
609complete -c tmux -n __fish_use_subcommand -a $pasteb -d 'paste buffer to pane'
610complete -c tmux -n __fish_use_subcommand -a $saveb -d 'save buffer to path'
611complete -c tmux -n __fish_use_subcommand -a $setb -d 'set buffer to value'
612complete -c tmux -n __fish_use_subcommand -a $showb -d 'print buffer to stdout'
613
614## commands with buffer flag
615complete -c tmux -n "__fish_seen_subcommand_from $deleteb $loadb $pasteb $saveb $setb $showb" -xs b -a '(__fish_tmux_buffers)' --keep-order -d 'buffer name'
616complete -c tmux -n "__fish_seen_subcommand_from $setb" -xs n -a '(__fish_tmux_buffers)' --keep-order -d 'new buffer name'
617
618## commands with target pane flag
619complete -c tmux -n "__fish_seen_subcommand_from $choosebuffer $clearhist $pasteb" -xs t --keep-order -a '(__fish_tmux_panes)' -d 'target pane'
620
621#commands with the -F format flag
622complete -c tmux -n "__fish_seen_subcommand_from $choosebuffer $lsb" -xs F -d 'format string'
623
624#commands with the -f filter flag
625complete -c tmux -n "__fish_seen_subcommand_from $choosebuffer $loadb $lsb" -xs f -d 'filter format string'
626
627# Commands that take paths
628complete -c tmux -n "__fish_seen_subcommand_from $loadb $saveb" --force-files
629
630###############  End:   Buffers ###############
631
632###############  Begin: Miscellaneous ###############
633#TODO - these commands are not currently implemented.
634#there is a section in the tmux man page that has the same title as this section
635#use the "Clients and Sessions" code as an example when implementing this
636###############  End:   Miscellaneous ###############