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

Re: capturing output of !! not working



On Thu, 19 Mar 2015 12:53:51 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Thu, 19 Mar 2015 08:27:56 -0400
> Vin Shelton <acs@xxxxxxxxxxxxxxxxxxxx> wrote:
> > The !! command now appears inside the $(),
> > but the output is not captured:
>
> This will be an effect of the history substitution turning up in the
> wrong place (hence you're seeing it on stdout which you shouldn't) owing
> to the interaction with the nested parsing.

Not quite --- it's another similar problem to the last, that history and
alias expansions are pushed onto the input stack in a similar way but
need different processing.  The new code is actually slightly more
efficient; inungetc() did too much work for the case in question.
The comment I've added is a distinct oversimplification, but I don't
want to write an essay.

I think what I'm seeing here is another symptom of the general
entanglement between input levels (that's been there since the start)
that's also been giving Bart headaches.

You *should* see the expansion on stdout, that's completely standard.
Because I always use HIST_VERIFY I'd forgotten.

It shouldn't be rocket science to simplify the zpty-based stuff to the
point where we have a framework for testing history.  However, the
baseline for what counts as rocket science is a little bit different in
these parts.

pws

diff --git a/Src/input.c b/Src/input.c
index 92b1ad1..30970a0 100644
--- a/Src/input.c
+++ b/Src/input.c
@@ -571,8 +571,20 @@ inpoptop(void)
 {
     if (!lexstop) {
 	inbufflags &= ~INP_ALCONT;
-	while (inbufptr > inbuf)
-	    inungetc(inbufptr[-1]);
+	while (inbufptr > inbuf) {
+	    inbufptr--;
+	    inbufct++;
+	    inbufleft++;
+	    /*
+	     * As elsewhere in input and history mechanisms:
+	     * unwinding aliases and unwinding history have different
+	     * implications as aliases are after the lexer while
+	     * history is before, but they're both pushed onto
+	     * the input stack.
+	     */
+	    if ((inbufflags & (INP_ALIAS|INP_HIST)) == INP_ALIAS)
+		zshlex_raw_back();
+	}
     }
 
     if (inbuf && (inbufflags & INP_FREE))



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