about summary refs log tree commit diff
path: root/Completion/Unix/Command/_tmux
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2017-08-18 04:23:45 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2017-08-30 00:13:06 +0000
commit73514c40f68fd7f66b64317d6e26793d400414ac (patch)
tree87fbd5c1b4a5e6b40d16ac7f67dac242a21a0dab /Completion/Unix/Command/_tmux
parent1e44c649a40f0e3e555bcd8941a22381b92a9c1f (diff)
downloadzsh-73514c40f68fd7f66b64317d6e26793d400414ac.tar.gz
zsh-73514c40f68fd7f66b64317d6e26793d400414ac.tar.xz
zsh-73514c40f68fd7f66b64317d6e26793d400414ac.zip
41567: _tmux: Complete detached sessions first for attach-session.
Diffstat (limited to 'Completion/Unix/Command/_tmux')
-rw-r--r--Completion/Unix/Command/_tmux21
1 files changed, 20 insertions, 1 deletions
diff --git a/Completion/Unix/Command/_tmux b/Completion/Unix/Command/_tmux
index 48fe29aee..f71f7c33e 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]"
 }
 
@@ -1373,6 +1373,25 @@ function __tmux-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}"