about summary refs log tree commit diff
path: root/Completion/Unix/Command/_chroot
blob: a9c577bd73a685d80d215b1cab39f63221c690ca (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
49
50
51
52
53
#compdef chroot gchroot

local variant ret=1
local -a context line state state_descr args
local -A opt_args

_pick_variant -r variant gnu='Free Soft' unix --version

variant+=-$OSTYPE

case $variant in
  gnu-*)
    args=(
      '(: -)--help[display help information]'
      '(: -)--version[display version information]'
      '--groups=[specify supplemental group memberships]: :_sequence -s , _groups'
      '--userspec=[specify user and group to run process as]: :->userspecs'
      '--skip-chdir[do not change working directory to /]'
    )
    ;;
  *-openbsd*)
    args=(
      '-u+[specify user to run process as]: :_users'
      '-g+[specify group to run process as, and supplemental group memberships]: :_sequence -s , _groups'
    )
    ;;
  *-(darwin|dragonfly|freebsd|netbsd)*)
    args=(
      '-u+[specify user to run process as]: :_users'
      '-g+[specify group to run process as]: :_groups'
      '-G+[specify supplemental group memberships]: :_sequence -s , _groups'
    )
    ;;
esac

args+=( '1:new root directory:_directories' '*::: : _normal -p $service' )

_arguments -s -S : $args && ret=0

# @todo user:group specs are probably used often enough to justify making a type
# function for this (see also `chown`, `cpio`, `rsync`, ...)
[[ $state == userspecs ]] &&
if compset -P '*:*:'; then
  ret=1
elif compset -P '*:'; then
  _groups && ret=0
elif compset -S ':*'; then
  _users && ret=0
else
  _users -qS : && ret=0
fi

return ret