about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-11-25 18:04:11 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-11-25 18:04:11 +0000
commitebce8a53238f034eabc110f6add3aaf16daf5a7f (patch)
treed5578bf1093fbfde1527954c7342dbe0a531d91b /Completion
parent95b2b55e8977d0fdc61866a62ce9b80a0e7798d3 (diff)
downloadzsh-ebce8a53238f034eabc110f6add3aaf16daf5a7f.tar.gz
zsh-ebce8a53238f034eabc110f6add3aaf16daf5a7f.tar.xz
zsh-ebce8a53238f034eabc110f6add3aaf16daf5a7f.zip
Merge of 23934: cleverer _expand_alias for "foo" -> "foo blah" expansions.
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Base/Completer/_expand_alias17
1 files changed, 16 insertions, 1 deletions
diff --git a/Completion/Base/Completer/_expand_alias b/Completion/Base/Completer/_expand_alias
index ee361d1bf..d950bf9f3 100644
--- a/Completion/Base/Completer/_expand_alias
+++ b/Completion/Base/Completer/_expand_alias
@@ -1,6 +1,7 @@
 #compdef -K _expand_alias complete-word \C-xa
 
 local word expl tmp pre sel what
+local -a tmpa
 
 eval "$_comp_setup"
 
@@ -42,10 +43,24 @@ if [[ -n $tmp ]]; then
   # We used to remove the quoting from the value in the parameter.
   # That was probably just an oversight: an alias is always replaced
   # literally.
+  tmp=${tmp%%[[:blank:]]##}
+  if [[ $tmp[1] = [[:alnum:]_] ]]; then
+    tmpa=(${(z)tmp})
+    if [[ $tmpa[1] = $word && $tmp = $aliases[$word] ]]; then
+      # This is an active regular alias and the first word in the result
+      # is the same as what was on the line already.  Quote it so
+      # that it doesn't get reexanded on execution.
+      #
+      # Strictly we also need to check if the original word matches
+      # a later word in the expansion and the previous words are
+      # all aliases where the expansion ends in " ", but I'm
+      # too lazy.
+      tmp="\\$tmp"
+    fi
+  fi
   $pre _wanted aliases expl alias compadd -UQ ${tmp%%[[:blank:]]##}
 elif (( $#pre )) && zstyle -t ":completion:${curcontext}:" complete; then
   $pre _aliases -s "$sel" -S ''
 else
   return 1
 fi
-