diff options
author | Felix Neumärker <xdch47@posteo.de> | 2019-01-18 23:18:02 +0100 |
---|---|---|
committer | William Hubbs <w.d.hubbs@gmail.com> | 2019-01-21 17:41:38 -0600 |
commit | 77f09900a2e0eeb1475e9ee404b6e7ff76ff8e9d (patch) | |
tree | 290dcf8709e6be4472a0501b9d43d6cc9c954786 | |
parent | 50d77a4e5d8c321cc89565295db13e60b2fb2cc7 (diff) |
zsh-completion: _rc-service fix flag/command combinations
- handle `rc-service -<flag> <service> <action>` correctly
This is for #285.
-rw-r--r-- | zsh-completion/_rc-service | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/zsh-completion/_rc-service b/zsh-completion/_rc-service index 25c6b4c5..b9976131 100644 --- a/zsh-completion/_rc-service +++ b/zsh-completion/_rc-service @@ -1,27 +1,32 @@ #compdef rc-service -if (( CURRENT == 2 )); then - _arguments -s \ - '(-e --exists)'{-e,--exists}"[tests if the service exists or not]" \ - '(-l --list)'{-l,--list}'[list all available services]' \ - '(-r --resolve)'{-r,--resolve}'[resolve the service name to an init script]' \ - '(-C --nocolor)'{-C,--nocolor}'[Disable color output]' \ - '(-v --verbose)'{-v,--verbose}'[Run verbosely]' \ - '(-q --quiet)'{-q,--quiet}'[Run quietly]' - _values "service" $(rc-service --list) -else - case $words[2] in - -e|--exists|-r|--resolve) - (( CURRENT > 3 )) && return 0 - _values "service" $(rc-service --list) - ;; - -*) - return 0 - ;; - *) - _values "action" stop start restart describe zap - ;; - esac -fi +_rc_services() { + if [[ -n "${opt_args[(i)-l|--list]}" ]]; then + _nothing + else + _values 'service' $(rc-service -l) + fi +} + +_rc_actions() { + local service="${line[1]}" + + if [[ -n "${opt_args[(i)-e|--exists|-r|--resolve]}" ]] || ! $(rc-service -e $service) ; then + _nothing + else + _values 'action' stop start restart describe zap + fi + +} + +_arguments -C -s \ + '(-e --exists)'{-e,--exists}'[tests if the service exists or not]' \ + '(-l --list)'{-l,--list}'[list all available services]' \ + '(-r --resolve)'{-r,--resolve}'[resolve the service name to an init script]' \ + '(-C --nocolor)'{-C,--nocolor}'[Disable color output]' \ + '(-v --verbose)'{-v,--verbose}'[Run verbosely]' \ + '(-q --quiet)'{-q,--quiet}'[Run quietly]' \ + '1:service:_rc_services' \ + '2:action:_rc_actions' # vim: set et sw=2 ts=2 ft=zsh: |