Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Word breaks around aliased tokens (was Re: PATCH: Removing aliases from history, 2015 style (was capturing output of !! not working))



On Mar 25, 12:40pm, Bart Schaefer wrote:
} 
} torch% echo foo&&bar
} foo foobar
} 
} If this were going to change, I would recommend using something akin to
} my patch from workers/34738 to add the second space, rather than attempt
} to remove the first one.

That would be as below, which is almost identical to 34738 (the salient
difference being use of INP_ALIAS instead of INP_CONT).

I think this makes sense[*]:

torch% alias -g '&&'=AND 
torch% echo foo&&bar    
foo AND bar

(the pre-patch output is "foo ANDbar") but I will wait for feedback before
pushing.

[*] To the extent I think aliasing these tokens makes sense at all.


diff --git a/Src/lex.c b/Src/lex.c
index 6d0079c..4c1555e 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -1747,6 +1747,16 @@ checkalias(void)
 	if (an && !an->inuse &&
 	    ((an->node.flags & ALIAS_GLOBAL) ||
 	     (incmdpos && tok == STRING) || inalmore)) {
+	    if (!lexstop) {
+		/*
+		 * Tokens that don't require a space after, get one,
+		 * because they are treated as if preceded by one.
+		 */
+		int c = hgetc();
+		hungetc(c);
+		if (!iblank(c))
+		    inpush(" ", INP_ALIAS, 0);
+	    }
 	    inpush(an->text, INP_ALIAS, an);
 	    if (an->text[0] == ' ' && !(an->node.flags & ALIAS_GLOBAL))
 		aliasspaceflag = 1;
diff --git a/Test/A02alias.ztst b/Test/A02alias.ztst
index fe7155e..08163eb 100644
--- a/Test/A02alias.ztst
+++ b/Test/A02alias.ztst
@@ -67,7 +67,7 @@
   fc -l -2' 2>/dev/null
 0:Aliasing reserved tokens
 >begin
->zsh: command not found: echoend
+>end
 *>*4*{ begin
 *>*5*{end
 



Messages sorted by: Reverse Date, Date, Thread, Author