about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBarton E. Schaefer <schaefer@zsh.org>2015-03-18 18:01:54 -0700
committerBarton E. Schaefer <schaefer@zsh.org>2015-03-18 18:01:54 -0700
commit32b4cb0e73cdb01c467a0484e906d28d7c104c64 (patch)
tree660b953e22bdb465731eef4af087beaf028a85ae
parent0b00462644a79194d67f87397548df8ff0c6c2c5 (diff)
downloadzsh-32b4cb0e73cdb01c467a0484e906d28d7c104c64.tar.gz
zsh-32b4cb0e73cdb01c467a0484e906d28d7c104c64.tar.xz
zsh-32b4cb0e73cdb01c467a0484e906d28d7c104c64.zip
34734: further aliasing adjustments and doc
restrict token aliasing (34641) to global aliases; tighten up POSIX_ALIASES to better match spec; update Aliasing doc to cover this and clarify older behavior

2015-03-18  Peter Stephenson  <p.stephenson@samsung.com>

	* 34723: configure.ac: turn off fixed site function directory if
-rw-r--r--ChangeLog7
-rw-r--r--Doc/Zsh/grammar.yo29
-rw-r--r--Src/lex.c10
-rw-r--r--Test/A02alias.ztst2
4 files changed, 35 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 871ef73eb..37d7c7962 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2015-03-18  Barton E. Schaefer  <schaefer@zsh.org>
+
+	* 34734: Doc/Zsh/grammar.yo, Src/lex.c, Test/A02alias.ztst:
+	restrict token aliasing (34641) to global aliases; tighten
+	up POSIX_ALIASES to better match spec; update Aliasing doc
+	to cover this and clarify older behavior
+
 2015-03-18  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 34723: configure.ac: turn off fixed site function directory if
diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo
index b30e423e1..522ad0472 100644
--- a/Doc/Zsh/grammar.yo
+++ b/Doc/Zsh/grammar.yo
@@ -538,8 +538,7 @@ If so, it is replaced by the text of the alias if it is in command
 position (if it could be the first word of a simple command),
 or if the alias is global.
 If the replacement text ends with a space, the next word in the shell input
-is treated as though it were in command position for purposes of alias
-expansion.
+is always eligible for purposes of alias expansion.
 findex(alias, use of)
 cindex(aliases, global)
 An alias is defined using the tt(alias) builtin; global aliases
@@ -555,22 +554,32 @@ itemiz(Any parameter reference or command substitution)
 itemiz(Any series of the foregoing, concatenated without whitespace or
 other tokens between them)
 itemiz(Any reserved word (tt(case), tt(do), tt(else), etc.))
+itemiz(With global aliasing, any command separator, any redirection
+operator, and `tt(LPAR())' or `tt(RPAR())' when not part of a glob pattern)
 enditemize()
 
-Reserved words are not eligible for aliasing when tt(POSIX_ALIASES) is set.
-The tt(alias) builtin does not reject ineligible aliases, but they are not
-expanded.
+It is not presently possible to alias the `tt(LPAR()LPAR())' token that
+introduces arithmetic expressions, because until a full statement has been
+parsed, it cannot be distinguished from two consecutive `tt(LPAR())'
+tokens introducing nested subshells.
+
+When tt(POSIX_ALIASES) is set, only plain unquoted strings are eligible
+for aliasing.  The tt(alias) builtin does not reject ineligible aliases,
+but they are not expanded.
 
 Alias expansion is done on the shell input before any other expansion
 except history expansion.  Therefore, if an alias is defined for the
 word tt(foo), alias expansion may be avoided by quoting part of the
 word, e.g. tt(\foo).  Any form of quoting works, although there is
 nothing to prevent an alias being defined for the quoted form such as
-tt(\foo) as well.  For use with completion, which would remove an
-initial backslash followed by a character that isn't special, it may be
-more convenient to quote the word by starting with a single quote,
-i.e. tt('foo); completion will automatically add the trailing single
-quote.
+tt(\foo) as well.  Also, if a separator such as tt(&&) is aliased,
+tt(\&&) turns into the two tokens tt(\&) and tt(&), each of which may
+have been aliased separately.  Similarly for tt(\<<), tt(\>|), etc.
+
+For use with completion, which would remove an initial backslash followed
+by a character that isn't special, it may be more convenient to quote the
+word by starting with a single quote, i.e. tt('foo); completion will
+automatically add the trailing single quote.
 
 There is a commonly encountered problem with aliases
 illustrated by the following code:
diff --git a/Src/lex.c b/Src/lex.c
index 494ea8870..1eb0bc7d7 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1740,12 +1740,13 @@ checkalias(void)
 
     if (!noaliases && isset(ALIASESOPT) &&
 	(!isset(POSIXALIASES) ||
-	 !reswdtab->getnode(reswdtab, zshlextext))) {
+	 (tok == STRING && !reswdtab->getnode(reswdtab, zshlextext)))) {
 	char *suf;
 
 	an = (Alias) aliastab->getnode(aliastab, zshlextext);
 	if (an && !an->inuse &&
-	    ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) {
+	    ((an->node.flags & ALIAS_GLOBAL) ||
+	     (incmdpos && tok == STRING) || inalmore)) {
 	    inpush(an->text, INP_ALIAS, an);
 	    if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL))
 		aliasspaceflag = 1;
@@ -1784,6 +1785,8 @@ exalias(void)
     if (!tokstr) {
 	zshlextext = tokstrings[tok];
 
+	if (tok == NEWLIN)
+	    return 0;
 	return checkalias();
     } else {
 	VARARR(char, copy, (strlen(tokstr) + 1));
@@ -1791,6 +1794,9 @@ exalias(void)
 	if (has_token(tokstr)) {
 	    char *p, *t;
 
+	    if (isset(POSIXALIASES))
+		return 0;
+
 	    zshlextext = p = copy;
 	    for (t = tokstr;
 		 (*p++ = itok(*t) ? ztokens[*t++ - Pound] : *t++););
diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst
index 36dfa241e..314ec036a 100644
--- a/Test/A02alias.ztst
+++ b/Test/A02alias.ztst
@@ -43,7 +43,7 @@
 0:Alias expansion works at the end of parsed strings
 >foo
 
-  alias '&&=(){ return $?; } && '
+  alias -g '&&=(){ return $?; } && '
   alias not_the_print_command=print
   eval 'print This is output
   && print And so is this