summaryrefslogtreecommitdiff
path: root/Completion/Unix/Command/_tmux
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Unix/Command/_tmux')
-rw-r--r--Completion/Unix/Command/_tmux282
1 files changed, 207 insertions, 75 deletions
diff --git a/Completion/Unix/Command/_tmux b/Completion/Unix/Command/_tmux
index 7ef20c666..730959e84 100644
--- a/Completion/Unix/Command/_tmux
+++ b/Completion/Unix/Command/_tmux
@@ -168,7 +168,7 @@ _tmux-attach-session() {
'-c+[specify working directory for the session]:directory:_directories' \
'-d[detach other clients attached to target session]' \
'-r[put the client into read-only mode]' \
- '-t+[specify target session]:target session:__tmux-sessions' \
+ '-t+[specify target session]:target session: __tmux-sessions-separately' \
"-E[don't apply update-environment option]"
}
@@ -178,19 +178,18 @@ _tmux-bind-key() {
'-c[bind to command mode instead of normal mode]' \
'-n[make the binding work without the need for the prefix key]' \
'-r[the key may repeat]' \
- '-t+[specify mode table for the binding]:mode table:__tmux-mode-tables' \
- '-R+[specify repeat count]:repeat count' \
'-T+[specify key table for the binding]:key table' \
'1:key' \
- '*:::template:_tmux'
+ '*:::template:= _tmux'
}
_tmux-break-pane() {
[[ -n ${tmux_describe} ]] && print "break a pane from an existing into a new window" && return
_arguments -s \
"-d[don't make the new window become the active one]" \
- '-F+[specify output format]:format:__tmux-format__tmux-format' \
+ '-F+[specify output format]:format:__tmux-format' \
'-P[print information of new window after it has been created]' \
+ '-n+[specify window name]:name' \
'-s+[specify source pane]:pane:__tmux-panes' \
'-t+[specify destination window]:pane:__tmux-panes'
}
@@ -212,49 +211,38 @@ _tmux-capture-pane() {
}
_tmux-choose-buffer() {
- [[ -n ${tmux_describe} ]] && print "put a window into buffer choice mode" && return
+ [[ -n ${tmux_describe} ]] && print "put a pane into buffer choice mode" && return
_arguments -s \
- '-F+[specify output format]:format:__tmux-format' \
+ '-N[start without the preview]' \
+ '-F+[specify format for each list item]:format:__tmux-formats' \
+ '-f+[filter items]:filter format:__tmux-formats' \
+ '-O+[initial sort order]:order:(time name size)' \
'-t+[specify target window]:session:__tmux-windows' \
- '*:::template:_tmux'
+ '*:::template:= _tmux'
}
_tmux-choose-client() {
[[ -n ${tmux_describe} ]] && print "put a window into client choice mode" && return
_arguments -s \
- '-F+[specify output format]:format:__tmux-format' \
- '-t+[specify target window]:session:__tmux-windows' \
- '*:::template:_tmux'
-}
-
-_tmux-choose-session() {
- [[ -n ${tmux_describe} ]] && print "put a window into session choice mode" && return
- _arguments -s \
- '-F+[specify output format]:format:__tmux-format' \
+ '-N[start without the preview]' \
+ '-F+[specify format for each list item]:format:__tmux-formats' \
+ '-f+[filter items]:filter format:__tmux-formats' \
+ '-O+[initial sort order]:order:(time name size)' \
'-t+[specify target window]:session:__tmux-windows' \
- '*:::template:_tmux'
+ '*:::template:= _tmux'
}
_tmux-choose-tree() {
[[ -n ${tmux_describe} ]] && print "put a window into tree choice mode" && return
_arguments -s \
- '-b+[override default session command]:session-command' \
- '-c+[override default window command]:window-command' \
- '-S+[specify session format]:session-format:__tmux-formats' \
+ '-N[start without the preview]' \
+ '-F+[specify format for each list item]:format:__tmux-formats' \
+ '-f+[filter items]:filter format:__tmux-formats' \
+ '-O+[initial sort order]:order:(time name size)' \
'-s[choose among sessions]' \
'-t+[specify target window]:session:__tmux-windows' \
- '-u[show generated tree uncollapsed at startup]' \
- '-W+[specify window format]:window-format:__tmux-formats' \
'-w[choose among windows]' \
- '*:::template:_tmux'
-}
-
-_tmux-choose-window() {
- [[ -n ${tmux_describe} ]] && print "put a window into window choice mode" && return
- _arguments -s \
- '-F=[specify output format]:format:__tmux-format' \
- '-t+[specify target window]:session:__tmux-windows' \
- '*:::template:_tmux'
+ '*:::template:= _tmux'
}
_tmux-clear-history() {
@@ -270,10 +258,13 @@ _tmux-clock-mode() {
_tmux-command-prompt() {
[[ -n ${tmux_describe} ]] && print "open the tmux command prompt in a client" && return
_arguments -s \
+ '-1[only accept one key press]' \
+ '-N' \
+ '-i[execute the command every time the prompt input changes]' \
'-I+[specify list of initial inputs]:initial-text (comma-separated list)' \
'-p+[specify list of prompts]:prompts (comma-separated list)' \
'-t+[specify target client]:client:__tmux-clients' \
- '*:::template:_tmux'
+ '*:::template:= _tmux'
}
_tmux-confirm-before() {
@@ -281,7 +272,7 @@ _tmux-confirm-before() {
_arguments -s \
'-p+[specify prompt]:prompt string' \
'-t+[specify target client]:client:__tmux-clients' \
- '*:::command:_tmux'
+ '*:::command:= _tmux'
}
_tmux-copy-mode() {
@@ -302,7 +293,8 @@ _tmux-detach-client() {
_arguments -s \
'-a[kill all clients except for the named by -t]' \
'-P[send SIGHUP to parent process]' \
- '-s+[specify target session and kill its clients]:session:__tmux-sessions' \
+ '-E+[run specified shell command to replace the client]:shell command:_cmdstring' \
+ '-s+[specify target session and kill its clients]:session:__tmux-sessions-attached' \
'-t+[specify target client]:client:__tmux-clients'
}
@@ -312,20 +304,22 @@ _tmux-display-message() {
'-c+[specify target client]:client:__tmux-clients' \
'-p[print message to stdout]' \
'-t+[specify target client]:client:__tmux-clients' \
- '-F+[specify output format]:format:__tmux-format' \
+ '-F+[specify output format]:format:__tmux-formats' \
':message'
}
_tmux-display-panes() {
[[ -n ${tmux_describe} ]] && print "display an indicator for each visible pane" && return
- _arguments '-t+[specify target client]:client:__tmux-clients'
+ _arguments -S \
+ '-d+[time to show indicator for]:duration (ms)' \
+ '-t+[specify target client]:client:__tmux-clients' \
+ '*:::command:= _tmux'
}
_tmux-find-window() {
[[ -n ${tmux_describe} ]] && print "search for a pattern in windows" && return
_arguments -s \
'-C[match visible contents]' \
- '-F+[specify output format]:format:__tmux-format' \
'-N[match window name]' \
'-T[match window title]' \
'-t+[specify target window]:window:__tmux-windows' \
@@ -417,13 +411,13 @@ _tmux-link-window() {
_tmux-list-buffers() {
[[ -n ${tmux_describe} ]] && print "list paste buffers of a session" && return
- _arguments '-F+[specify output format]:format:__tmux-format'
+ _arguments '-F+[specify output format]:format:__tmux-formats'
}
_tmux-list-clients() {
[[ -n ${tmux_describe} ]] && print "list clients attached to server" && return
_arguments -s \
- '-F+[specify output format]:format:__tmux-format' \
+ '-F+[specify output format]:format:__tmux-formats' \
'-t+[specify session]:session:__tmux-sessions'
}
@@ -435,7 +429,6 @@ _tmux-list-commands() {
_tmux-list-keys() {
[[ -n ${tmux_describe} ]] && print "list all key-bindings" && return
_arguments -s \
- '-t+[specify mode table]:mode table:__tmux-mode-tables' \
'-T+[specify key table]:key table'
}
@@ -449,20 +442,20 @@ _tmux-list-panes() {
fi
_arguments -s $args \
'-a[list all panes the server possesses]' \
- '-F+[specify output format]:format:__tmux-format' \
+ '-F+[specify output format]:format:__tmux-formats' \
'-s[if specified, -t chooses a session]'
}
_tmux-list-sessions() {
[[ -n ${tmux_describe} ]] && print "list sessions managed by server" && return
- _arguments '-F+[specify output format]:format:__tmux-format'
+ _arguments '-F+[specify output format]:format:__tmux-formats'
}
_tmux-list-windows() {
[[ -n ${tmux_describe} ]] && print "list windows of a session" && return
_arguments -s \
'-a[list all windows the tmux server possesses]' \
- '-F[specify output format]:format:__tmux-format' \
+ '-F[specify output format]:format:__tmux-formats' \
'-t+[specify session]:session:__tmux-sessions'
}
@@ -519,7 +512,7 @@ _tmux-new-session() {
"-d[don't attach new session to current terminal]" \
"-D[in case of -A behave like attach-session's -d]" \
"-E[don't apply update-environment option]" \
- '-F+[specify output format]:format:__tmux-format' \
+ '-F+[specify output format]:format:__tmux-formats' \
'-n+[specify initial window name]:window name' \
'-P[print information about new session after it is created]' \
'-s+[name the session]:session name:__tmux-sessions' \
@@ -535,7 +528,7 @@ _tmux-new-window() {
'-a[insert new window at next free index from -t]' \
'-c+[specify working directory for the session]:directory:_directories' \
"-d[don't make the new window become the active one]" \
- '-F+[specify output format]:format:__tmux-format' \
+ '-F+[specify output format]:format:__tmux-formats' \
'-k[destroy it if the specified window exists]' \
'-n+[specify a window name]:window name' \
'-P[print information about new window after it is created]' \
@@ -626,6 +619,7 @@ _tmux-resize-pane() {
_tmux-respawn-pane() {
[[ -n ${tmux_describe} ]] && print "reuse a pane in which a command has exited" && return
_arguments -s -A "-*" -S \
+ '-c+[specify a new working directory for the pane]:directory:_directories' \
'-k[kill window if it is in use]' \
'-t+[specify target pane]:pane:__tmux-pane' \
':command:_cmdambivalent'
@@ -634,6 +628,7 @@ _tmux-respawn-pane() {
_tmux-respawn-window() {
[[ -n ${tmux_describe} ]] && print "reuse a window in which a command has exited" && return
_arguments -s -A "-*" -S \
+ '-c+[specify a new working directory for the window]:directory:_directories' \
'-k[kill window if it is in use]' \
'-t+[specify target window]:window:__tmux-windows' \
':command:_cmdambivalent'
@@ -686,6 +681,7 @@ _tmux-select-pane() {
'-R[move to the pane right of target]' \
'-U[move to the pane above target]' \
'-P+[set pane style]:style:__tmux-style' \
+ '-T+[set the pane title]:title' \
'-t+[specify target pane]:pane:__tmux-panes'
}
@@ -705,6 +701,8 @@ _tmux-send-keys() {
'-l[disable key name lookup and send data literally]' \
'-R[reset terminal state]' \
'-M[pass through a mouse event]' \
+ '-X[send a command into copy mode]' \
+ '-N+[specify repeat count]:repeat count' \
'-t+[specify target pane]:pane:__tmux-panes' \
'*:key'
}
@@ -732,12 +730,33 @@ _tmux-set-buffer() {
_tmux-set-environment() {
[[ -n ${tmux_describe} ]] && print "(un)set an environment variable" && return
- _arguments -s -A "-*" -S \
- '-g[modify global environment]' \
- '-r[remove variable before starting new processes]' \
- '-u[unset a variable]' \
- '-t[specify target session]:target session:__tmux-sessions' \
- ':name' ':value'
+ local mode=session action=add
+ local curcontext="$curcontext" state line ret=1
+ typeset -A opt_args
+ _arguments -C -s -A "-*" -S : \
+ '(-t)-g[modify global environment]' \
+ '(-u)-r[remove variable before starting new processes]' \
+ '(-r)-u[unset a variable]' \
+ '(-g)-t[specify target session]:target session:__tmux-sessions' \
+ ': :->name' '(-u -r)2: :->value' && ret=0
+
+ if (( ${+opt_args[-g]} )); then
+ mode=global
+ fi
+ if (( ${+opt_args[-u]} )); then
+ action=unset
+ fi
+ if (( ${+opt_args[-r]} )); then
+ action=remove
+ fi
+
+ # TODO: the exclusion "(-g -r)2:" doesn't work, so simulate it here
+ if [[ $action == (remove|unset) ]] && [[ $state == value ]]; then
+ __tmux-nothing-else
+ else
+ __tmux-environment-variables $mode $state $action && ret=0
+ fi
+ return ret
}
_tmux-set-option() {
@@ -745,8 +764,9 @@ _tmux-set-option() {
local mode=session
local curcontext="$curcontext" state line ret=1
typeset -A opt_args
- _arguments -C -s \
+ _arguments -C -s : \
'-a[append to string options]' \
+ '-F[expand formats in the option value]' \
'-g[set a global session option]' \
'-o[prevent setting of an option that is already set]' \
'-q[suppress errors about unknown or ambiguous options]' \
@@ -769,8 +789,9 @@ _tmux-set-window-option() {
[[ -n ${tmux_describe} ]] && print "set a window option" && return
local curcontext="$curcontext" state line ret=1
typeset -A opt_args
- _arguments -C -s \
+ _arguments -C -s : \
'-a[append to string options]' \
+ '-F[expand formats in the option value]' \
'-g[set a global window option]' \
'-o[prevent setting of an option that is already set]' \
'-q[suppress errors about unknown or ambiguous options]' \
@@ -785,8 +806,10 @@ _tmux-set-hook() {
[[ -n ${tmux_describe} ]] && print "set a hook to a command" && return
_arguments -s \
'-g[add hook to global list]' \
- '-t+[specify target session]:session:__tmux-sessions'
- ':command'
+ '-u[unset a hook]' \
+ '-t+[specify target session]:session:__tmux-sessions' \
+ ':hook name:_tmux_hooks' \
+ '*:::command:= _tmux'
}
_tmux-show-hooks() {
@@ -794,7 +817,6 @@ _tmux-show-hooks() {
_arguments -s -S -A "-*" \
'-g[show global list of hooks]' \
'-t+[specify target session]:session:__tmux-sessions' \
- ':hook name:(alert-activity alert-bell alert-silence client-attached client-detached client-resized pane-died pane-exited)' \
}
_tmux-show-buffer() {
@@ -804,10 +826,21 @@ _tmux-show-buffer() {
_tmux-show-environment() {
[[ -n ${tmux_describe} ]] && print "display the environment" && return
- _arguments -s \
- '-g[show global environment]' \
+ local mode=session
+ local curcontext="$curcontext" state line ret=1
+ typeset -A opt_args
+ _arguments -C -A "-*" -s : \
+ '(-t)-g[show global environment]' \
'-s[format output as Bourne shell commands]' \
- '-t+[specify target session]:target session:__tmux-sessions'
+ '(-g)-t+[specify target session]:target session:__tmux-sessions' \
+ '1:: :->name' && ret=0
+
+ if (( ${+opt_args[-g]} )); then
+ mode=global
+ fi
+
+ __tmux-environment-variables $mode $state show && ret=0
+ return ret
}
_tmux-show-messages() {
@@ -820,21 +853,38 @@ _tmux-show-messages() {
_tmux-show-options() {
[[ -n ${tmux_describe} ]] && print "show session options" && return
- _arguments -s \
+ local mode=session
+ local curcontext="$curcontext" state line ret=1
+ typeset -A opt_args
+ _arguments -C -s : \
'-g[show global options]' \
'-q[suppress errors about unknown or ambiguous options]' \
'-s[show server options]' \
'-v[show only the option value, not the name]' \
'-w[show window options]' \
- '-t+[specify target session]:target session:__tmux-sessions'
+ '-t+[specify target session]:target session:__tmux-sessions' \
+ '*:: :->name_or_value' && ret=0
+
+ if (( ${+opt_args[-w]} )); then
+ mode=window
+ elif (( ${+opt_args[-s]} )); then
+ mode=server
+ fi
+ __tmux-options-complete ${mode} ${state} && ret=0
+ return ret
}
_tmux-show-window-options() {
[[ -n ${tmux_describe} ]] && print "show window options" && return
- _arguments -s \
+ local curcontext="$curcontext" state line ret=1
+ typeset -A opt_args
+ _arguments -C -s : \
'-g[show global options]' \
'-v[show only the option value, not the name]' \
- '-t+[specify target window]:target window:__tmux-windows'
+ '-t+[specify target window]:target window:__tmux-windows' \
+ '*:: :->name_or_value' && ret=0
+ __tmux-options-complete window ${state} && ret=0
+ return ret
}
_tmux-source-file() {
@@ -849,7 +899,8 @@ _tmux-split-window() {
_arguments -s \
'-b[create new pane left of or above target pane]' \
"-d[don't make the new window become the active one]" \
- '-F+[specify output format]:format:__tmux-format' \
+ '-F+[specify output format]:format:__tmux-formats' \
+ '-f[create new pane spanning full window width or height]' \
'-h[split horizontally]' \
'-v[split vertically]' \
"-l[define new pane's size]:size" \
@@ -910,9 +961,7 @@ _tmux-unbind-key() {
ow=( "${words[@]}" )
_arguments -C -s \
'-a[remove all key bindings]' \
- '-c[kill the window if it is only in one session]' \
'-n[remove a non-prefix binding]' \
- '-t+[specify mode table]:mode table:__tmux-mode-tables' \
'-T[specify key table]:key table' \
'*:: :->boundkeys'
@@ -980,8 +1029,65 @@ function __tmux-clients() {
_describe -t clients 'clients' clients
}
-function __tmux-format() {
- _message 'not implemented yet'
+function __tmux-environment-variables() {
+ local mode="$1" state="$2" action="$3"
+
+ local -a dash_g
+ case $mode in
+ (global) dash_g=(-g);;
+ (session) dash_g=();;
+ (*) return 1;; # bug in the caller
+ esac
+
+ local hint
+ case $action in
+ (add|remove) hint=" (or specify a new one)";;
+ (unset|show) hint="";;
+ (*) return 1;; # bug in the caller
+ esac
+
+ case ${state} in
+ (name)
+ local -a vars_and_vals=( ${(@f)"$(command tmux 2>/dev/null show-env $dash_g)"} )
+ local -a descriptions
+ local k_v k v
+ for k_v in $vars_and_vals; do
+ k=${k_v%%=*}
+ if [[ $k == -* ]]; then
+ k=${k#-}
+ v='(remove)'
+ else
+ v=${k_v#*=}
+ fi
+ descriptions+=( "${k//:/\\:}:$v" )
+ done
+ # TODO: this if/else is because '_describe ${hint:+"-x"}' prints the "No matches" error in addition to the message.
+ local msg="${dash_g[1]:+"global "}environment variables${hint}"
+ if _describe -t parameters $msg descriptions; then
+ :
+ elif [[ -n $hint ]]; then
+ _message $msg
+ fi
+ ;;
+ (value)
+ local var_and_val=${(@f)"$(command tmux 2>/dev/null show-env $dash_g -- ${(Q)words[-2]})"}
+ # TODO: this if/else is because '_description -x' prints the "No matches" error in addition to the message.
+ if [[ -n $var_and_val ]]; then
+ local -a expl
+ _description -x parameter-values expl "Value for ${words[-2]}"
+ compadd "$expl[@]" - ${var_and_val#*=}
+ else
+ _message "Value for ${words[-2]}"
+ fi
+ ;;
+ (*)
+ return 1
+ ;;
+ esac
+}
+
+__tmux-formats() {
+ _message 'not implemented yet'
}
function __tmux-colours() {
@@ -995,6 +1101,12 @@ function __tmux-colours() {
fi
}
+_tmux_hooks() {
+ _alternative \
+ 'hooks:hook name:(alert-activity alert-bell alert-silence client-attached client-detached client-resized client-session-changed pane-died pane-exited pane-set-clipboard session-created session-closed session-renamed window-linked window-renamed window-unlinked)' \
+ 'post-hooks:command post-hook:compadd - after-${_tmux_aliasmap}'
+}
+
function __tmux-get-optarg() {
local opt="$1"
local -i i
@@ -1010,12 +1122,6 @@ function __tmux-get-optarg() {
done
}
-__tmux-mode-tables() {
- local expl
- _description mode-tables expl 'mode table'
- compadd "$@" "$expl[@]" vi-edit emacs-edit vi-choice emacs-choice vi-copy emacs-copy
-}
-
__tmux-nothing-else() {
_message "no further arguments"
}
@@ -1260,6 +1366,32 @@ function __tmux-sessions() {
_describe -t sessions 'sessions' sessions "$@"
}
+function __tmux-sessions-attached() {
+ local -a sessions
+ sessions=( ${${(f)"$(command tmux 2> /dev/null list-sessions)"}/:[ $'\t']##/:} )
+ sessions=( ${(M)sessions:#*"(attached)"} )
+ _describe -t sessions 'attached sessions' sessions "$@"
+}
+
+# Complete attached-sessions and detached-sessions as separate tags.
+function __tmux-sessions-separately() {
+ local ret=1
+ local -a sessions detached_sessions attached_sessions
+ sessions=( ${${(f)"$(command tmux 2> /dev/null list-sessions)"}/:[ $'\t']##/:} )
+ detached_sessions=( ${sessions:#*"(attached)"} )
+ attached_sessions=( ${(M)sessions:#*"(attached)"} )
+
+ # ### This seems to work without a _tags loop but not with it. I suspect
+ # ### that has something to do with _describe doing its own _tags loop.
+ _tags detached-sessions attached-sessions
+ # Placing detached before attached means the default behaviour of this
+ # function better suits its only current caller, _tmux-attach-session().
+ _requested detached-sessions && _describe -t detached-sessions 'detached sessions' detached_sessions "$@" && ret=0
+ _requested attached-sessions && _describe -t attached-sessions 'attached sessions' attached_sessions "$@" && ret=0
+
+ return ret
+}
+
function __tmux-socket-name() {
local expl sdir
local curcontext="${curcontext}"