__babysit_sessions() {
local -a sessions
local __bs_dir="$HOME/.babysit/sessions"
if [[ -d "$__bs_dir" ]]; then
for sess in "$__bs_dir"/*(N/); do
sessions+=("${sess:t}")
done
fi
sessions+=("latest")
_describe 'session' sessions
}
_babysit() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
'1: :->subcmd' \
'*:: :->args'
case $state in
subcmd)
local -a subcmds
subcmds=(
'run:Wrap a shell command in a PTY'
'list:List all babysit sessions'
'ls:List all babysit sessions'
'status:Show status of a session'
'st:Show status of a session'
'info:Show status of a session'
'log:Show recent output from the wrapped command'
'logs:Show recent output from the wrapped command'
'restart:Restart the wrapped command'
'r:Restart the wrapped command'
'kill:Terminate the wrapped command'
'stop:Terminate the wrapped command'
'send:Send text to the wrapped command stdin'
'type:Send text to the wrapped command stdin'
'prune:Delete finished or dead sessions'
'upgrade:Self-update to the latest version'
'config:Output shell integration (eval "$(babysit config zsh)")'
)
_describe 'subcommand' subcmds
;;
args)
case ${words[1]} in
run)
_arguments \
'--id=[Session id to assign]:id:' \
'(-d --detach)'{-d,--detach}'[Run detached in the background]' \
'(-)1:command:_command_names -e' \
'*::arguments:_normal'
;;
list|ls)
_arguments '--json[Output as JSON]'
;;
status|st|info)
_arguments \
'(-s --session)'{-s,--session}'[Session id]:session:__babysit_sessions' \
'--json[Output as JSON]'
;;
log|logs)
_arguments \
'(-s --session)'{-s,--session}'[Session id]:session:__babysit_sessions' \
'--tail=[Show only the last N lines]:lines:' \
'--raw[Include raw ANSI escapes]'
;;
restart|r|kill|stop|send|type)
_arguments \
'(-s --session)'{-s,--session}'[Session id]:session:__babysit_sessions'
;;
prune)
_arguments '--dry-run[Print what would be deleted, but do not delete]'
;;
config)
if (( CURRENT == 2 )); then
local -a shells
shells=('zsh:Zsh integration' 'bash:Bash integration')
_describe 'shell' shells
fi
;;
esac
;;
esac
}
compdef _babysit babysit