summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--Doc/Zsh/options.yo37
-rw-r--r--Src/lex.c6
-rw-r--r--Src/options.c1
-rw-r--r--Src/zsh.h1
-rw-r--r--Test/A02alias.ztst11
6 files changed, 58 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 445e80cca..97d2f3383 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-03-03  Peter Stephenson  <pws@csr.com>
 
+	* Doc/Zsh/options.yo, Src/lex.c, Src/options.c, Src/zsh.h,
+	Test/A02alias.ztst: add POSIX_ALIASES option.
+
 	* 26671: Completion/Zsh/Command/_zattr, Doc/Zsh/.distfiles,
 	Src/Modules/attr.c: various minor tidy-ups (tidies up?) for
 	26670.
@@ -11308,5 +11311,5 @@
 
 *****************************************************
 * This is used by the shell to define $ZSH_PATCHLEVEL
-* $Revision: 1.4593 $                         
+* $Revision: 1.4594 $                         
 *****************************************************
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index c6b4c5d69..70038c8c6 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1708,6 +1708,43 @@ is not and will replace the first element of the array.
 This option is for compatibility with older versions of the shell and
 is not recommended in new code.
 )
+pindex(POSIX_ALIASES)
+pindex(NO_POSIX_ALIASES)
+pindex(POSIXALIASES)
+pindex(NOPOSIXALIASES)
+item(tt(POSIX_ALIASES) <K> <S>)(
+When this option is set, reserved words are not candidates for
+alias expansion:  it is still possible to declare any of them as an alias,
+but the alias will never be expanded.  Reserved words are
+tt(!),
+tt([[),
+tt({),
+tt(}),
+tt(case),
+tt(coproc),
+tt(do),
+tt(done),
+tt(elif),
+tt(else),
+tt(end),
+tt(esac),
+tt(fi),
+tt(for),
+tt(foreach),
+tt(function),
+tt(if),
+tt(nocorrect),
+tt(repeat),
+tt(select),
+tt(then),
+tt(time),
+tt(until),
+tt(while).
+
+Alias expansion takes place while text is being read; hence when this
+option is set it does not take effect until the end of any function or
+other piece of shell code evaluated as one unit.
+)
 pindex(POSIX_BUILTINS)
 pindex(NO_POSIX_BUILTINS)
 pindex(POSIXBUILTINS)
diff --git a/Src/lex.c b/Src/lex.c
index 466447963..f7e87477a 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1748,9 +1748,11 @@ exalias(void)
 
 	if (tok == STRING) {
 	    /* Check for an alias */
-	    if (!noaliases && isset(ALIASESOPT)) {
+	    if (!noaliases && isset(ALIASESOPT) &&
+		(!isset(POSIXALIASES) ||
+		 !reswdtab->getnode(reswdtab, zshlextext))) {
 		char *suf;
-		
+
 		an = (Alias) aliastab->getnode(aliastab, zshlextext);
 		if (an && !an->inuse &&
 		    ((an->node.flags & ALIAS_GLOBAL) || incmdpos || inalmore)) {
diff --git a/Src/options.c b/Src/options.c
index f852ec830..d310f346d 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -198,6 +198,7 @@ static struct optname optns[] = {
 {{NULL, "octalzeroes",        OPT_EMULATE|OPT_SH},	 OCTALZEROES},
 {{NULL, "overstrike",	      0},			 OVERSTRIKE},
 {{NULL, "pathdirs",	      OPT_EMULATE},		 PATHDIRS},
+{{NULL, "posixaliases",       OPT_EMULATE|OPT_BOURNE},	 POSIXALIASES},
 {{NULL, "posixbuiltins",      OPT_EMULATE|OPT_BOURNE},	 POSIXBUILTINS},
 {{NULL, "posixidentifiers",   OPT_EMULATE|OPT_BOURNE},	 POSIXIDENTIFIERS},
 {{NULL, "printeightbit",      0},                        PRINTEIGHTBIT},
diff --git a/Src/zsh.h b/Src/zsh.h
index 0b9007333..8d2deec6c 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1933,6 +1933,7 @@ enum {
     OCTALZEROES,
     OVERSTRIKE,
     PATHDIRS,
+    POSIXALIASES,
     POSIXBUILTINS,
     POSIXIDENTIFIERS,
     PRINTEIGHTBIT,
diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst
index 0c2a464c9..231e13771 100644
--- a/Test/A02alias.ztst
+++ b/Test/A02alias.ztst
@@ -25,3 +25,14 @@
   \bar \bar
 0:Aliasing with a backslash
 >bar
+
+  (alias '!=echo This command has the argument'
+  eval 'print Without
+  ! true'
+  setopt posixaliases
+  eval 'print With
+  ! true')
+1:POSIX_ALIASES option
+>Without
+>This command has the argument true
+>With