| 1 |
_unshare_module() |
| 2 |
{ |
| 3 |
local cur prev words cword |
| 4 |
local OPTS NOARGOPTS OPTARGOPTS REQARGOPTS REQARGOPTS_SHORT NOARGOPTS_SHORT |
| 5 |
_init_completion -n = -- "$@" || return |
| 6 |
|
| 7 |
OPTARGOPTS="--mount=|--uts=|--ipc=|--net=|--pid=|--user=|--cgroup=|--time=|--kill-child=|--mount-proc=|--mount-binfmt=" |
| 8 |
|
| 9 |
REQARGOPTS="--owner|--propagation|--setgroups|--root|--wd|--load-interp|--map-group|--map-groups|--map-user|--map-users|--monotonic|--boottime|--setuid|--setgid" |
| 10 |
|
| 11 |
REQARGOPTS_SHORT="-l|-R|-w|-S|-G" |
| 12 |
|
| 13 |
NOARGOPTS="--fork|--forward-signals|--map-root-user|--map-current-user|--map-auto|--map-subids|--keep-caps|--help|--version|${OPTARGOPTS//=/}" |
| 14 |
|
| 15 |
NOARGOPTS_SHORT="-r|-f|-c|-h|-V|-m|-u|-i|-n|-p|-U|-C|-T" |
| 16 |
|
| 17 |
OPTS="${NOARGOPTS//[|]/ } ${NOARGOPTS_SHORT//[|]/ } ${OPTARGOPTS//[|]/ } ${REQARGOPTS//[|]/ } ${REQARGOPTS_SHORT//[|]/ }" |
| 18 |
|
| 19 |
# Check if we are still completing unshare(1) and set |
| 20 |
# the offset so that it points to the command that is |
| 21 |
# going to be executed, in order to complete it with |
| 22 |
# its own completion specification. |
| 23 |
local offset=0 i |
| 24 |
for ((i = 1; i < cword; i++)); do |
| 25 |
if [[ "${words[i]}" =~ ^--$ ]]; then |
| 26 |
((i++)) |
| 27 |
elif [[ "${words[i]}" =~ ^($NOARGOPTS|$NOARGOPTS_SHORT)$ ]]; then |
| 28 |
continue |
| 29 |
elif [[ "${words[i]}" =~ ^($OPTARGOPTS).* ]]; then |
| 30 |
continue |
| 31 |
elif [[ "${words[i]}" =~ ^($REQARGOPTS|$REQARGOPTS_SHORT)$ ]]; then |
| 32 |
[[ "${words[$((i+1))]}" != -* ]] && ((i++)) |
| 33 |
continue |
| 34 |
fi |
| 35 |
offset=$i |
| 36 |
break |
| 37 |
done |
| 38 |
|
| 39 |
if (( offset > 0 )); then |
| 40 |
# Find completion specification for the wrapped command |
| 41 |
_command_offset $offset |
| 42 |
else |
| 43 |
# $OPTARGOPTS deserve special treatment due |
| 44 |
# to the '=' that delimits the actual argument |
| 45 |
# that we wish to complete and the option name |
| 46 |
if [[ "$cur" =~ ^($OPTARGOPTS).* ]]; then |
| 47 |
# Cut also backslash before '=' in case it ended up there |
| 48 |
# for some reason. |
| 49 |
prev=${cur%%?(\\)=*} |
| 50 |
cur=${cur#*=} |
| 51 |
|
| 52 |
compopt -o nospace |
| 53 |
case $prev in |
| 54 |
'--kill-child') |
| 55 |
COMPREPLY=( $(compgen -A signal -- $cur) ) |
| 56 |
return 0 |
| 57 |
;; |
| 58 |
*) |
| 59 |
COMPREPLY=( $(compgen -f -d -- $cur) ) |
| 60 |
return 0 |
| 61 |
;; |
| 62 |
esac |
| 63 |
fi |
| 64 |
|
| 65 |
case $prev in |
| 66 |
'--propagation') |
| 67 |
COMPREPLY=( $(compgen -W "slave shared private unchanged" -- $cur) ) |
| 68 |
return 0 |
| 69 |
;; |
| 70 |
'--setgroups') |
| 71 |
COMPREPLY=( $(compgen -W "allow deny" -- $cur) ) |
| 72 |
return 0 |
| 73 |
;; |
| 74 |
'-w'|'--wd'|'-l'|'--load-interp'|'-R'|'--root') |
| 75 |
# It's better than simply using 'compgen -f', |
| 76 |
# because it honours spaces in filenames. |
| 77 |
_filedir |
| 78 |
return 0 |
| 79 |
;; |
| 80 |
'-S'|'--setuid') |
| 81 |
local uids |
| 82 |
uids="$(awk -F: '{print $3}' /etc/passwd | sort --numeric-sort)" |
| 83 |
COMPREPLY=( $(compgen -W "$uids" -- $cur) ) |
| 84 |
return 0 |
| 85 |
;; |
| 86 |
'-G'|'--setgid') |
| 87 |
local gids |
| 88 |
gids="$(awk -F: '{print $3}' /etc/group | sort --numeric-sort)" |
| 89 |
COMPREPLY=( $(compgen -W "$gids" -- $cur) ) |
| 90 |
return 0 |
| 91 |
;; |
| 92 |
'-h'|'--help'|'-V'|'--version') |
| 93 |
return 0 |
| 94 |
;; |
| 95 |
esac |
| 96 |
|
| 97 |
if [[ "$cur" == -* ]]; then |
| 98 |
COMPREPLY=( $(compgen -W "${OPTS[*]}" -- $cur) ) |
| 99 |
return 0 |
| 100 |
else |
| 101 |
COMPREPLY=( $(compgen -c -- "$cur") ) |
| 102 |
fi |
| 103 |
fi |
| 104 |
return 0 |
| 105 |
} |
| 106 |
complete -F _unshare_module -o bashdefault -o default unshare |