1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2026-01-09 22:51:15 +01:00
zsh/Completion/Base/Utility/_call_program
Oliver Kiddle 8011fe8a58 39261 (tweaked cf. Daniel: 39275): don't unconditionally elevate privileges with sudo in completion functions
A new gain-privileges style enables it and a _comp_priv_prefix array
added for tracking how to match privileges for the current command
2016-09-11 13:49:22 +02:00

33 lines
611 B
Text

#autoload +X
local tmp err_fd=-1
local -a prefix
if [[ "$1" = -p ]]; then
shift
zstyle -t ":completion:${curcontext}:${1}" gain-privileges &&
prefix=( $_comp_priv_prefix )
fi
if (( ${debug_fd:--1} > 2 )) || [[ ! -t 2 ]]
then exec {err_fd}>&2 # debug_fd is saved stderr, 2 is trace or redirect
else exec {err_fd}>/dev/null
fi
{ # Begin "always" block
if zstyle -s ":completion:${curcontext}:${1}" command tmp; then
if [[ "$tmp" = -* ]]; then
eval "$tmp[2,-1]" "$argv[2,-1]"
else
eval $prefix "$tmp"
fi
else
eval $prefix "$argv[2,-1]"
fi 2>&$err_fd
} always {
exec {err_fd}>&-
}