diff --git a/compdef/_sv b/compdef/_sv new file mode 100644 index 0000000..8ec03c8 --- /dev/null +++ b/compdef/_sv @@ -0,0 +1,48 @@ +#compdef sv + +# completion for runit sv(1) +# Christian Neukirchen +# runit 2.1.1, services in /var/service are completed by default + +local ret=1 services + +_arguments \ + '-v[verbose]' \ + '-w[wait]:seconds' \ + '1: :->cmds' \ + '*:: :->args' && ret=0 + +case $state in +cmds) + _values "sv command" \ + status \ + up \ + down \ + once \ + pause cont hup alarm interrupt quit 1 2 term kill \ + exit + # above allow one-character shortcuts, complete these + [[ $words[CURRENT] = [sudopchaiq12tke] ]] || + _values "sv command" \ + start \ + stop \ + restart \ + shutdown \ + force-stop \ + force-reload \ + force-restart \ + force-shutdown \ + check + ret=0;; +args) + if [[ $UID == 0 || $BUFFER == sudo* ]] then + services=( /var/service/*(-/N:t) ) + else + services=( ~/.service/*(-/N) ) + fi + (( $#services )) && _values services $services && ret=0 + [[ $words[CURRENT] = */* ]] && _directories && ret=0 + ;; +esac + +return $ret