Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tmux): Add completion for alias functions #12278

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions plugins/tmux/tmux.plugin.zsh
Expand Up @@ -57,6 +57,43 @@ function _build_tmux_alias {
}"
}

# ALIAS COMPLETION (Modified from https://github.com/zsh-users/zsh)
_tmux-attach-session() {
[[ -n ${tmux_describe} ]] && print "attach or switch to a session" && return

local sessions
sessions=(${(f)"$(tmux list-session)"})

if (( CURRENT == 2 )); then
_alternative \
'commands:: _describe -t sessions "tmux session" sessions'
return
fi

if [[ $words[1] =~ ta ]]; then
_arguments -s \
'1:session' \
'-c+[specify working directory for the session]:directory:_directories' \
'-d[detach other clients attached to target session]' \
'-f+[set client flags]: :_tmux_client_flags' \
'-r[put the client into read-only mode]' \
"-E[don't apply update-environment option]" \
'-x[with -d, send SIGHUP to the parent of the attached client]'
elif [[ $words[1] = "tkss" ]]; then
_arguments -s \
'1:session' \
'-a[kill all session except the one specified by -t]' \
'-C[clear alerts (bell, activity, silence) in all windows linked to the session]'
fi

return
}

_tmux_client_flags() {
_values -s , flag active-pane ignore-size no-output \
'pause-after:time (seconds)' read-only wait-exit
}

alias tksv='tmux kill-server'
alias tl='tmux list-sessions'
alias tmuxconf='$EDITOR $ZSH_TMUX_CONFIG'
Expand Down Expand Up @@ -130,6 +167,10 @@ function _zsh_tmux_plugin_run() {

# Use the completions for tmux for our function
compdef _tmux _zsh_tmux_plugin_run

# Provide session name completion for alias functions.
compdef _tmux-attach-session ta tad tkss

# Alias tmux to our wrapper function.
alias tmux=_zsh_tmux_plugin_run

Expand Down