diff options
author | Matthew Martin <phy1729@gmail.com> | 2019-03-19 20:42:35 -0500 |
---|---|---|
committer | Matthew Martin <phy1729@gmail.com> | 2019-03-21 22:04:55 -0500 |
commit | 922cf4983081e46af20075034bd6f5f670d1a2f7 (patch) | |
tree | 7f99fcd63aef07b64e5998f8afd28863ba6f79a1 /Completion/Base | |
parent | 3e542bcd818c57785aa4cc7c5e6be3b92118fb7d (diff) | |
download | zsh-922cf4983081e46af20075034bd6f5f670d1a2f7.tar.gz zsh-922cf4983081e46af20075034bd6f5f670d1a2f7.tar.xz zsh-922cf4983081e46af20075034bd6f5f670d1a2f7.zip |
44155: _pick_variant: Update builtin check
Diffstat (limited to 'Completion/Base')
-rw-r--r-- | Completion/Base/Utility/_pick_variant | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/Completion/Base/Utility/_pick_variant b/Completion/Base/Utility/_pick_variant index 9099e3599..872e8f583 100644 --- a/Completion/Base/Utility/_pick_variant +++ b/Completion/Base/Utility/_pick_variant @@ -1,9 +1,15 @@ #autoload -local output cmd pat +local output cmd pat pre local -a var local -A opts +# Precommands which allow their wrapped command to be a builtin. +# All of these are necessarily builtins or reserved words themselves, +# but not all builtin precommands are listed here: +# for one, the 'command' builtin is excluded. +local -ar builtin_precommands=(- builtin eval exec nocorrect noglob time) + (( $+_cmd_variant )) || typeset -gA _cmd_variant zparseopts -D -A opts b: c: r: @@ -13,19 +19,27 @@ while [[ $1 = *=* ]]; do var+=( "${1%%\=*}" "${1#*=}" ) shift done -if (( $+_cmd_variant[$opts[-c]] )); then - (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}" - [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1 + +if (( ${#precommands:|builtin_precommands} )); then + pre=command +elif (( $+opts[-b] && ( $precommands[(I)builtin] || $+builtins[$opts[-c]] ) )); then + (( $+opts[-r] )) && eval "${opts[-r]}=$opts[-b]" return 0 +elif (( $precommands[(I)builtin] )); then + pre=builtin +else + # Neither builtin nor command-forcing precommand specified, + # so no prefix is needed. + pre= fi -if [[ $+opts[-b] -eq 1 && -n $builtins[$opts[-c]] ]]; then - _cmd_variant[$opts[-c]]=$opts[-b] +if [[ $pre != builtin ]] && (( $+_cmd_variant[$opts[-c]] )); then (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}" + [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1 return 0 fi -output="$(_call_program variant $opts[-c] "${@[2,-1]}" </dev/null 2>&1)" +output="$(_call_program variant $pre $opts[-c] "${@[2,-1]}" </dev/null 2>&1)" for cmd pat in "$var[@]"; do if [[ $output = *$~pat* ]]; then @@ -36,6 +50,6 @@ for cmd pat in "$var[@]"; do done (( $+opts[-r] )) && eval "${opts[-r]}=$1" -_cmd_variant[$opts[-c]]="$1" +[[ $pre != builtin ]] && _cmd_variant[$opts[-c]]="$1" return 1 |