summaryrefslogtreecommitdiffstats
path: root/completions/sudo
diff options
context:
space:
mode:
Diffstat (limited to 'completions/sudo')
-rw-r--r--completions/sudo38
1 files changed, 20 insertions, 18 deletions
diff --git a/completions/sudo b/completions/sudo
index c9a806b..2cfcf84 100644
--- a/completions/sudo
+++ b/completions/sudo
@@ -1,56 +1,58 @@
# bash completion for sudo(8) -*- shell-script -*-
-_sudo()
+_comp_cmd_sudo()
{
- local cur prev words cword split
- _init_completion -s || return
+ local cur prev words cword was_split comp_args
+ _comp_initialize -s -- "$@" || return
local i mode=normal
[[ $1 == *sudoedit ]] && mode=edit
+ local noargopts='!(-*|*[uUgCp]*)'
[[ $mode == normal ]] &&
for ((i = 1; i <= cword; i++)); do
if [[ ${words[i]} != -* ]]; then
local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
- local root_command=${words[i]}
- _command_offset $i
+ local _comp_root_command=$1
+ _comp_command_offset $i
return
fi
- if [[ ${words[i]} == -@(!(-*)e*|-edit) ]]; then
+ # shellcheck disable=SC2254
+ if [[ ${words[i]} == -@(${noargopts}e*|-edit) ]]; then
mode=edit
break
fi
- [[ ${words[i]} == \
- -@(user|other-user|group|close-from|prompt|!(-*)[uUgCp]) ]] &&
+ # shellcheck disable=SC2254
+ [[ ${words[i]} == @(--@(user|other-user|group|close-from|prompt)|-${noargopts}[uUgCp]) ]] &&
((i++))
done
+ # shellcheck disable=SC2254
case "$prev" in
- --user | --other-user | -!(-*)[uU])
- COMPREPLY=($(compgen -u -- "$cur"))
+ --user | --other-user | -${noargopts}[uU])
+ _comp_compgen -- -u
return
;;
- --group | -!(-*)g)
- COMPREPLY=($(compgen -g -- "$cur"))
+ --group | -${noargopts}g)
+ _comp_compgen -- -g
return
;;
- --close-from | --prompt | -!(-*)[Cp])
+ --close-from | --prompt | -${noargopts}[Cp])
return
;;
esac
- $split && return
+ [[ $was_split ]] && return
if [[ $cur == -* ]]; then
- local opts=$(_parse_help "$1")
- COMPREPLY=($(compgen -W '${opts:-$(_parse_usage "$1")}' -- "$cur"))
+ _comp_compgen_help || _comp_compgen_usage
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
return
fi
if [[ $mode == edit ]]; then
- _filedir
+ _comp_compgen_filedir
fi
} &&
- complete -F _sudo sudo sudoedit
+ complete -F _comp_cmd_sudo sudo sudoedit
# ex: filetype=sh