Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] _pick_variant: Update builtin check



Move the builtin check prior to the cache lookup and don't cache
builtins if -b is provided. This corrects the result if a user uses both
a builtin and external version of a command in one shell session.

The command may be builtin only if all precommands are
builtin-preserving which are enumerated in builtin_precommands.
Since a builtin-preserving precommand must be itself builtin, I figure
it's easier to maintain as a white list. This corrects the case Daniel
brought up: command chmod <tab>.

I'll split out the _builtin change before commit. Wasn't large enough to
get its own mail but necessary if anyone is testing.

- Matthew Martin

---
 Completion/Base/Utility/_pick_variant | 15 +++++++++------
 Completion/Zsh/Command/_builtin       |  2 ++
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/Completion/Base/Utility/_pick_variant b/Completion/Base/Utility/_pick_variant
index 9099e3599..f4ceb7462 100644
--- a/Completion/Base/Utility/_pick_variant
+++ b/Completion/Base/Utility/_pick_variant
@@ -1,9 +1,11 @@
 #autoload
 
 local output cmd pat
-local -a var
+local -a builtin_precommands var
 local -A opts
 
+builtin_precommands=(- builtin eval exec nocorrect noglob time)
+
 (( $+_cmd_variant )) || typeset -gA _cmd_variant
 
 zparseopts -D -A opts b: c: r:
@@ -13,15 +15,16 @@ 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 (( $+opts[-b] && ! ${#precommands:|builtin_precommands} &&
+    ( $+builtins[$opts[-c]] || $precommands[(I)builtin] ) )); then
+  (( $+opts[-r] )) && eval "${opts[-r]}=$opts[-b]"
   return 0
 fi
 
-if [[ $+opts[-b] -eq 1 && -n $builtins[$opts[-c]] ]]; then
-  _cmd_variant[$opts[-c]]=$opts[-b]
+if (( $+_cmd_variant[$opts[-c]] )); then
   (( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
+  [[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1
   return 0
 fi
 
diff --git a/Completion/Zsh/Command/_builtin b/Completion/Zsh/Command/_builtin
index 9fb6acf7b..a77af9879 100644
--- a/Completion/Zsh/Command/_builtin
+++ b/Completion/Zsh/Command/_builtin
@@ -1,5 +1,7 @@
 #compdef builtin
 
+precommands+=(builtin)
+
 if (( $CURRENT > 2 )); then
   shift words
   (( CURRENT -- ))
-- 
2.21.0



Messages sorted by: Reverse Date, Date, Thread, Author