1#compdef chroot gchroot
2
3local variant ret=1
4local -a context line state state_descr args
5local -A opt_args
6
7_pick_variant -r variant gnu='Free Soft' unix --version
8
9variant+=-$OSTYPE
10
11case $variant in
12  gnu-*)
13    args=(
14      '(: -)--help[display help information]'
15      '(: -)--version[display version information]'
16      '--groups=[specify supplemental group memberships]: :_sequence -s , _groups'
17      '--userspec=[specify user and group to run process as]: :->userspecs'
18      '--skip-chdir[do not change working directory to /]'
19    )
20    ;;
21  *-openbsd*)
22    args=(
23      '-u+[specify user to run process as]: :_users'
24      '-g+[specify group to run process as, and supplemental group memberships]: :_sequence -s , _groups'
25    )
26    ;;
27  *-(darwin|dragonfly|freebsd|netbsd)*)
28    args=(
29      '-u+[specify user to run process as]: :_users'
30      '-g+[specify group to run process as]: :_groups'
31      '-G+[specify supplemental group memberships]: :_sequence -s , _groups'
32    )
33    ;;
34esac
35
36args+=( '1:new root directory:_directories' '*:::command:_normal' )
37
38_arguments -s -S : $args && ret=0
39
40# @todo user:group specs are probably used often enough to justify making a type
41# function for this (see also `chown`, `cpio`, `rsync`, ...)
42[[ $state == userspecs ]] &&
43if compset -P '*:*:'; then
44  ret=1
45elif compset -P '*:'; then
46  _groups && ret=0
47elif compset -S ':*'; then
48  _users && ret=0
49else
50  _users -qS : && ret=0
51fi
52
53return ret
54