aboutsummaryrefslogtreecommitdiff
path: root/zsh-completion/_rc-service
blob: 1c518fa186c0518ced210b1b73798b37fc15bbd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#compdef rc-service

_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
    local -a actions=(${(f)"$(rc-service -C $service describe 2>&1)"})
    shift actions
    actions=(${actions# \* })
    actions=(${actions/:*})
    actions=(stop start restart describe zap ${actions[@]})
    _describe -V 'action' actions
  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: