mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-18 15:21:16 +02:00
* Update _command_names to add **/sbin to PATH when not otherwise overridden and _comp_priv_prefix is set. This ensures that, on systems where unprivileged users don't have **/sbin in their PATHs, we can still complete those commands when they try to run them with e.g. sudo * Update functions for privilege-gaining commands to use the aforementioned mechanism * Fix some other minor issues in _pfexec and _doas Changes from the posted diff: * Fix a minor redundancy in _doas * Add _c_p_p=( '' ) hack to _su
36 lines
803 B
Text
36 lines
803 B
Text
#compdef pfexec
|
|
|
|
# This is a _values-like function that completes privileges and !-prefixed
|
|
# privileges, comma-separated, and unique.
|
|
_privset() {
|
|
local expl p
|
|
local -a privs
|
|
|
|
privs=( ${(f)"$(ppriv -l)"} all none zone basic )
|
|
|
|
# Ignore existing values
|
|
compset -P '*,'
|
|
# Ignore a leading !, maybe backslash-quoted
|
|
compset -P '\\#!'
|
|
|
|
# Remove already-referenced privs
|
|
for p in ${(s:,:)${IPREFIX//\\#\!/}}; do
|
|
privs=( ${privs:#$p} )
|
|
done
|
|
|
|
_wanted privs expl 'privilege' compadd -qS , -a privs
|
|
}
|
|
|
|
_pfexec() {
|
|
local cmd cpp
|
|
local -a _comp_priv_prefix
|
|
local -A opt_args
|
|
cmd="$words[1]"
|
|
cpp='_comp_priv_prefix=( $cmd ${(kv)opt_args[(I)-P]} )'
|
|
_arguments \
|
|
'-P+[privileges to acquire]:privspec:_privset' \
|
|
"(-): :{ $cpp; _command_names -e }" \
|
|
"*:: :{ $cpp; _normal }"
|
|
}
|
|
|
|
_pfexec "$@"
|