_workmux_handles() {
local -a handles
handles=("${(@f)$(workmux _complete-handles 2>/dev/null)}")
handles=(${handles:#})
(( ${#handles} )) && compadd -a handles
}
_workmux_agent_targets() {
local -a targets
targets=("${(@f)$(workmux _complete-agent-targets 2>/dev/null)}")
targets=(${targets:#})
(( ${#targets} )) && compadd -a targets
}
_workmux_git_branches() {
local -a branches
branches=("${(@f)$(workmux _complete-git-branches 2>/dev/null)}")
branches=(${branches:#})
(( ${#branches} )) && compadd -a branches
}
_workmux() {
emulate -L zsh
setopt extended_glob setopt no_nomatch
local cmd="${words[2]}"
local -a arg_flags
case "$cmd" in
add)
arg_flags=(
-p --prompt
-P --prompt-file
--name
-a --agent
-n --count
--foreach
--branch-template
--pr
)
;;
open)
arg_flags=(
-p --prompt
-P --prompt-file
)
;;
merge)
arg_flags=(
)
;;
*)
arg_flags=()
;;
esac
if [[ "${words[CURRENT]}" == -* ]] || [[ -n "${arg_flags[(r)${words[CURRENT-1]}]}" ]]; then
_workmux_base "$@"
return
fi
case "$cmd" in
open|remove|rm|path|merge|close)
_workmux_handles
;;
send|capture|status|wait|run)
_workmux_agent_targets
;;
add)
_workmux_git_branches
;;
*)
_workmux_base "$@"
;;
esac
}
if [ "$funcstack[1]" = "_workmux" ]; then
_workmux "$@"
else
compdef _workmux workmux
fi