about summary refs log tree commit diff
path: root/Completion/Unix/Command/_sudo
blob: ee238b462bc868eeefb1c8a53d83251f6784b4c3 (plain) (blame)
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
38
39
40
41
42
43
44
45
46
47
48
#compdef sudo sudoedit

local environ e
local -a args

zstyle -a ":completion:${curcontext}:" environ environ

for e in "${environ[@]}"
do local -x "$e"
done

args=(
  '(-A --askpass)'{-A,--askpass}'[use a helper program for password prompting]'
  '(-C --close-from)'{-C+,--close-from=}'[close file descriptors]:lowest fd to close'
  '(-g --group)'{-g+,--group=}'[run command as the specified group name or ID]:group:_groups'
  '(-)'{-h,--help}'[display help message and exit]'
  '(-h --host)'{-h+,--host=}'[run command on host]:host:_hosts'
  '(-K --remove-timestamp)'{-K,--remove-timestamp}'[remove timestamp file completely]'
  '(-k --reset-timestamp)'{-k,--reset-timestamp}'[invalidate timestamp file]'
  \*{-l,--list}"[list user's privileges or check a specific command]"
  '(-n --non-interactive)'{-n,--non-interactive}'[non-interactive mode, no prompts are used]'
  '(-p --prompt)'{-p+,--prompt=}'[use the specified password prompt]:prompt'
  '(-r --role)'{-r+,--role=}'[create SELinux security context with specified role]:role'
  '(-S --stdin)'{-S,--stdin}'[read password from standard input]'
  '(-t --type)'{-t+,--type=}'[create SELinux security context with specified type]:type'
  '(-U --other-user)'{-U+,--other-user=}'[in list mode, display privileges for user]:user:_users'
  '(-u --user)'{-u+,--user=}'[run command (or edit file) as specified user]:user:_users'
  '(-)'{-V,--version}'[display version information and exit]'
  '(-v --validate)'{-v,--validate}"[update user's timestamp without running a command]"
)

if [[ $service = sudoedit || -n ${words[(r)-e]} ]]; then
  args=( -A "-*" $args '!(-V --version -h --help)-e' '*:file:_files' )
else
  args+=(
    '(-e --edit 1 *)'{-e,--edit}'[edit files instead of running a command]' \
    '(-s --shell)'{-s,--shell}'[run shell as the target user; a command may also be specified]' \
    '(-i --login)'{-i,--login}'[run login shell as the target user; a command may also be specified]' \
    '(-b --background -i --login -s --shell -e --edit)'{-b,--background}'[run command in the background]' \
    '(-E --preserve-env -i --login -s --shell -e --edit)'{-E,--preserve-env}'[preserve user environment when running command]' \
    '(-H --set-home -i --login -s --shell -e --edit)'{-H,--set-home}"[set HOME variable to target user's home dir]" \
    '(-P --preserve-groups -i -login -s --shell -e --edit)'{-P,--preserve-groups}"[preserve group vector instead of setting to target's]" \
    '(-)1:command: _command_names -e'
    '*::arguments: _normal'
  )
fi

_arguments -s -S $args