Here is my script:
#!/usr/bin/env bash
kill-all-sessions() {
tmux kill-server
}
kill-other-sessions() {
tmux kill-session -a
}
kill-unattached-sessions() {
tmux list-sessions -F '#{session_name} #{session_attached}' | awk '$2 == 0 { print $1 }' | xargs -n1 tmux kill-session -t
}
list-attached-sessions() {
tmux list-sessions -F "#{session_attached} #{session_name} #{session_path}" | awk '$1 == 1 { print $2, $3 }'
}
# Main logic: check the argument and call the corresponding function
case "$1" in
kill-all)
kill-all-sessions
;;
kill-other)
kill-other-sessions
;;
kill-unattached)
kill-unattached-sessions
;;
list-attached)
list-attached-sessions
;;
*)
echo "Usage: $0 {kill-all|kill-other|kill-unattached|list-attached}"
exit 1
;;
esac
I need a zsh completion function for this script.
The code I came up with is:
#compdef tmux-manager
_tmux-manager() {
local -a commands
commands=(
'kill-all:Kill all tmux sessions'
'kill-other:Kill all sessions except the current one'
'kill-unattached:Kill only unattached sessions'
'list-attached:List only attached sessions'
)
_describe 'command' commands
}
_tmux-manager "$@"
The code is not working. What might be the solution.