zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH 1/2] alias -L: Emit aliases that begin with a plus sign correctly.
@ 2016-11-24  6:57 Daniel Shahaf
  2016-11-24  6:57 ` [PATCH 2/2] builtins: Say 'bad option: +x', not 'bad option: -x', when +x was passed Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Shahaf @ 2016-11-24  6:57 UTC (permalink / raw)
  To: zsh-workers

---
Without this series:

% alias -- +foo=42
% alias -L
alias +foo=42
alias run-help=man
alias which-command=whence
% eval $(alias -L)
zsh: bad option: -f

Reported as z-sy-h issue #392.

Sideline: how to make the workflow 
    x=`alias -L`
    unalias -m \*
    ...
    eval $x
work under released versions, that have this bug?

This is for z-sy-h, so the ellipsis is sourced with user settings in effect,
and needs to change global state.  Ideas so far are to define an 'alias'
function [but that would overwrite a user-defined function by that name]; to
use 'zcompile -U' or 'autoload -U' with a second file; or to somehow arrange
for aliases that begin with a '+' to be exempted from being undefined and from
being redefined.

Cheers,

Daniel

 Src/hashtable.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Src/hashtable.c b/Src/hashtable.c
index 2d5af5b..7c33675 100644
--- a/Src/hashtable.c
+++ b/Src/hashtable.c
@@ -1291,9 +1291,9 @@ printaliasnode(HashNode hn, int printflags)
 	else if (a->node.flags & ALIAS_GLOBAL)
 	    printf("-g ");
 
-	/* If an alias begins with `-', then we must output `-- ' *
+	/* If an alias begins with `-' or `+', then we must output `-- '
 	 * first, so that it is not interpreted as an option.     */
-	if(a->node.nam[0] == '-')
+	if(a->node.nam[0] == '-' || a->node.nam[0] == '+')
 	    printf("-- ");
     }
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] builtins: Say 'bad option: +x', not 'bad option: -x', when +x was passed.
  2016-11-24  6:57 [PATCH 1/2] alias -L: Emit aliases that begin with a plus sign correctly Daniel Shahaf
@ 2016-11-24  6:57 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2016-11-24  6:57 UTC (permalink / raw)
  To: zsh-workers

---
 Src/builtin.c      | 5 +++--
 Test/A02alias.ztst | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/Src/builtin.c b/Src/builtin.c
index ab159ad..e641a97 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -249,7 +249,7 @@ int
 execbuiltin(LinkList args, LinkList assigns, Builtin bn)
 {
     char *pp, *name, *optstr;
-    int flags, sense, argc, execop, xtr = isset(XTRACE);
+    int flags, argc, execop, xtr = isset(XTRACE);
     struct options ops;
 
     /* initialise options structure */
@@ -294,6 +294,7 @@ execbuiltin(LinkList args, LinkList assigns, Builtin bn)
 	/* Sort out the options. */
 	if (optstr) {
 	    char *arg = *argv;
+	    int sense; /* 1 for -x, 0 for +x */
 	    /* while arguments look like options ... */
 	    while (arg &&
 		   /* Must begin with - or maybe + */
@@ -387,7 +388,7 @@ execbuiltin(LinkList args, LinkList assigns, Builtin bn)
 		if (*arg) {
 		    if(*arg == Meta)
 			*++arg ^= 32;
-		    zwarnnam(name, "bad option: -%c", *arg);
+		    zwarnnam(name, "bad option: %c%c", "+-"[sense], *arg);
 		    return 1;
 		}
 		arg = *++argv;
diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst
index 1e09cd3..e52578e 100644
--- a/Test/A02alias.ztst
+++ b/Test/A02alias.ztst
@@ -110,3 +110,8 @@
 127:No endless loop with suffix alias in command position
 >You said it.
 ?(eval):1: command not found: thingummy.mysuff
+
+  alias +x; alias -z
+1:error message has the correct sign
+?(eval):alias:1: bad option: +x
+?(eval):alias:1: bad option: -z


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-11-24  7:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-24  6:57 [PATCH 1/2] alias -L: Emit aliases that begin with a plus sign correctly Daniel Shahaf
2016-11-24  6:57 ` [PATCH 2/2] builtins: Say 'bad option: +x', not 'bad option: -x', when +x was passed Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).