about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-10-11 09:06:19 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-10-11 09:06:19 +0000
commitaf3e2b6fa4f8db6d5bdb2273180d5030ba00c0d3 (patch)
tree2e4431244a337cbdea1e58eb47bc3a85b94802b3
parentc05028c195325abcaa4dcb0d1a3d7dd9c3d7627d (diff)
downloadzsh-af3e2b6fa4f8db6d5bdb2273180d5030ba00c0d3.tar.gz
zsh-af3e2b6fa4f8db6d5bdb2273180d5030ba00c0d3.tar.xz
zsh-af3e2b6fa4f8db6d5bdb2273180d5030ba00c0d3.zip
23934: cleveren _expand_alias for "foo" -> "foo blah" expansions
-rw-r--r--ChangeLog6
-rw-r--r--Completion/Base/Completer/_expand_alias17
-rw-r--r--Doc/Zsh/expn.yo15
3 files changed, 32 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 5f50cb29e..a066ad4dd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-10-11  Peter Stephenson  <pws@csr.com>
+
+	* 23934: Completion/Base/Completer/_expand_alias:
+	if "foo" expands as regular alias to "foo blah", turn this
+	into "\foo blah" to avoid the alias kicking in again.
+
 2007-10-08  Clint Adams  <clint@zsh.org>
 
 	* 23923: Src/Modules/curses.c: fold all other curses windowing
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
-
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index cff393c57..cc87ebe6f 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -1229,12 +1229,17 @@ that minimum width.  If the numbers are in decreasing order the
 resulting sequence will also be in decreasing order.
 
 If a brace expression matches none of the above forms, it is left
-unchanged, unless the tt(BRACE_CCL) option is set.
+unchanged, unless the option tt(BRACE_CCL) (an abbreviation for `brace
+character class') is set.
 pindex(BRACE_CCL, use of)
-In that case, it is expanded to a sorted list of the individual
-characters between the braces, in the manner of a search set.
-`tt(-)' is treated specially as in a search set, but `tt(^)' or `tt(!)' as
-the first character is treated normally.
+In that case, it is expanded to a list of the individual
+characters between the braces sorted into the order of the characters
+in the ASCII character set (multibyte characters are not currently
+handled).  The syntax is similar to a
+tt([)...tt(]) expression in filename generation:
+`tt(-)' is treated specially to denote a range of characters, but `tt(^)' or
+`tt(!)' as the first character is treated normally.  For example,
+`tt({abcdef0-9})' expands to 16 words tt(0 1 2 3 4 5 6 7 8 9 a b c d e f).
 
 Note that brace expansion is not part of filename generation (globbing); an
 expression such as tt(*/{foo,bar}) is split into two separate words