diff options
author | Oliver Kiddle <opk@zsh.org> | 2016-09-11 13:22:35 +0200 |
---|---|---|
committer | Oliver Kiddle <opk@zsh.org> | 2016-09-11 13:49:22 +0200 |
commit | 8011fe8a582bd3c018a98e0e2c08f65233bcf0fc (patch) | |
tree | ce6612c1e1bc5e6618b86e8d0b7b7743714b09c9 /Completion/Base | |
parent | f368720b8b9b481f82cef2e84a7e035864dff5f1 (diff) | |
download | zsh-8011fe8a582bd3c018a98e0e2c08f65233bcf0fc.tar.gz zsh-8011fe8a582bd3c018a98e0e2c08f65233bcf0fc.tar.xz zsh-8011fe8a582bd3c018a98e0e2c08f65233bcf0fc.zip |
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
Diffstat (limited to 'Completion/Base')
-rw-r--r-- | Completion/Base/Core/_main_complete | 1 | ||||
-rw-r--r-- | Completion/Base/Utility/_call_program | 11 |
2 files changed, 10 insertions, 2 deletions
diff --git a/Completion/Base/Core/_main_complete b/Completion/Base/Core/_main_complete index 9c4cfac85..c292ce7d7 100644 --- a/Completion/Base/Core/_main_complete +++ b/Completion/Base/Core/_main_complete @@ -38,6 +38,7 @@ local func funcs ret=1 tmp _compskip format nm call match min max i num\ _saved_colors="$ZLS_COLORS" \ _saved_colors_set=${+ZLS_COLORS} \ _ambiguous_color='' +local -a _comp_priv_prefix # _precommand sets this to indicate we are following a precommand modifier local -a precommands diff --git a/Completion/Base/Utility/_call_program b/Completion/Base/Utility/_call_program index 010e09476..95c761e65 100644 --- a/Completion/Base/Utility/_call_program +++ b/Completion/Base/Utility/_call_program @@ -1,6 +1,13 @@ #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 @@ -13,10 +20,10 @@ if zstyle -s ":completion:${curcontext}:${1}" command tmp; then if [[ "$tmp" = -* ]]; then eval "$tmp[2,-1]" "$argv[2,-1]" else - eval "$tmp" + eval $prefix "$tmp" fi else - eval "$argv[2,-1]" + eval $prefix "$argv[2,-1]" fi 2>&$err_fd } always { |