mscs/mscs.completion
2017-06-14 09:27:51 -06:00

64 lines
1.9 KiB
Plaintext

list_worlds() {
$MSCS ls $1 | sed -n '/:/{s/^ *//;s/:.*$//;p}'
}
_mscs() {
local OPTS WORLDS
MSCS="$1"
COMPREPLY=()
COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
OPTS="
backup console create delete disable enable force-restart force-stop list
list-backups logrotate map new overviewer remove restart restore-backup
broadcast send show start status stop sync update force-update watch usage
"
LIST_OPTS="enabled disabled running stopped"
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=($(compgen -W "$OPTS" -- ${COMP_WORDS[COMP_CWORD]}))
elif [ $COMP_CWORD -eq 2 ]; then
case ${COMP_WORDS[COMP_CWORD-1]} in
start)
WORLDS=$(list_worlds stopped)
COMPREPLY=($(compgen -W "$WORLDS" -- ${COMP_WORDS[COMP_CWORD]}))
;;
stop|force-stop|restart|force-restart|send|console)
WORLDS=$(list_worlds running)
COMPREPLY=($(compgen -W "$WORLDS" -- ${COMP_WORDS[COMP_CWORD]}))
;;
disable|sync|send|watch|logrotate|backup|map|overviewer|\
list-backups|restore-backup|update|force-update)
WORLDS=$(list_worlds enabled)
COMPREPLY=($(compgen -W "$WORLDS" -- ${COMP_WORDS[COMP_CWORD]}))
;;
status|show|remove|delete)
WORLDS=$(list_worlds)
COMPREPLY=($(compgen -W "$WORLDS" -- ${COMP_WORDS[COMP_CWORD]}))
;;
enable)
WORLDS=$(list_worlds disabled)
COMPREPLY=($(compgen -W "$WORLDS" -- ${COMP_WORDS[COMP_CWORD]}))
;;
ls|list)
COMPREPLY=($(compgen -W "$LIST_OPTS" -- ${COMP_WORDS[COMP_CWORD]}))
;;
*)
;;
esac
elif [ $COMP_CWORD -eq 3 ]; then
case ${COMP_WORDS[COMP_CWORD-2]} in
restore-backup)
BACKUPS=$($MSCS list-backups "${COMP_WORDS[COMP_CWORD-1]}")
COMPREPLY=($(compgen -W "$BACKUPS" -- "${COMP_WORDS[COMP_CWORD]}"))
;;
*)
;;
esac
fi
return 0
}
complete -F _mscs msctl mscs