]> git.ipfire.org Git - thirdparty/util-linux.git/blob - bash-completion/setpriv
bash-completion: handle comma-separated options
[thirdparty/util-linux.git] / bash-completion / setpriv
1 _setpriv_module()
2 {
3 local cur prev OPTS
4 COMPREPLY=()
5 cur="${COMP_WORDS[COMP_CWORD]}"
6 prev="${COMP_WORDS[COMP_CWORD-1]}"
7 case $prev in
8 '--inh-caps'|'--bounding-set')
9 local prefix realcur INHERIT_ALL INHERIT
10 realcur="${cur##*,}"
11 prefix="${cur%$realcur}"
12 INHERIT_ALL=$($1 --list-caps| awk '{print $1, "-" $1}')
13 for WORD in $INHERIT_ALL; do
14 if ! [[ $prefix == *"$WORD"* ]]; then
15 INHERIT="$WORD $INHERIT"
16 fi
17 done
18 compopt -o nospace
19 COMPREPLY=( $(compgen -P "$prefix" -W "$INHERIT" -S ',' -- $realcur) )
20 return 0
21 ;;
22 '--ruid'|'--euid'|'--reuid')
23 local UIDS
24 UIDS=$(getent passwd | awk -F: '{print $3}')
25 COMPREPLY=( $(compgen -W "$UIDS" -- $cur) )
26 return 0
27 ;;
28 '--rgid'|'--egid'|'--regid')
29 local GIDS
30 GIDS=$(getent group | awk -F: '{print $3}')
31 COMPREPLY=( $(compgen -W "$GIDS" -- $cur) )
32 return 0
33 ;;
34 '--groups')
35 local prefix realcur GIDS_ALL GIDS
36 realcur="${cur##*,}"
37 prefix="${cur%$realcur}"
38 GIDS_ALL=$(getent group | awk -F: '{print $3}')
39 for WORD in $GIDS_ALL; do
40 if ! [[ $prefix == *"$WORD"* ]]; then
41 GIDS="$WORD $GIDS"
42 fi
43 done
44 compopt -o nospace
45 COMPREPLY=( $(compgen -P "$prefix" -W "$GIDS" -S ',' -- $realcur) )
46 return 0
47 ;;
48 '--securebits')
49 local SBITS
50 SBITS="noroot noroot_locked no_setuid_fixup no_setuid_fixup_locked keep_caps_locked
51 -noroot -noroot_locked -no_setuid_fixup -no_setuid_fixup_locked -keep_caps_locked"
52 COMPREPLY=( $(compgen -W "$SBITS" -- $cur) )
53 return 0
54 ;;
55 '--selinux-label')
56 # FIXME: how to list selinux labels?
57 COMPREPLY=( $(compgen -W "label" -- $cur) )
58 return 0
59 ;;
60 '--apparmor-profile')
61 # FIXME: how to list apparmor profiles?
62 COMPREPLY=( $(compgen -W "profile" -- $cur) )
63 return 0
64 ;;
65 '-h'|'--help'|'-V'|'--version')
66 return 0
67 ;;
68 esac
69 case $cur in
70 -*)
71 OPTS="--dump
72 --no-new-privs
73 --inh-caps
74 --bounding-set
75 --ruid
76 --euid
77 --rgid
78 --egid
79 --reuid
80 --regid
81 --clear-groupsclear
82 --keep-groupskeep
83 --groups
84 --securebits
85 --selinux-label
86 --apparmor-profile
87 --help
88 --version"
89 COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) )
90 return 0
91 ;;
92 esac
93 compopt -o bashdefault
94 COMPREPLY=( $(compgen -c -- $cur) )
95 return 0
96 }
97 complete -F _setpriv_module setpriv