Zsh Mailing List Archive
Messages sorted by:
Re: [PATCH] Add execute-command() widget function (was Re: [RFC][PATCH] Add change-directory() widget function)
- X-seq: zsh-workers 48733
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Marlon Richert <marlon.richert@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] Add execute-command() widget function (was Re: [RFC][PATCH] Add change-directory() widget function)
- Date: Tue, 27 Apr 2021 12:27:48 -0700
- Archived-at: <https://zsh.org/workers/48733>
- In-reply-to: <CAHLkEDtgMYYVdtHBiPDYbhdhwRH9Ha3T1ix+G_q_=-miNgo=PA@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <95CDA630-4EE5-4003-8D9C-CCCB9A47F109@gmail.com> <CAH+w=7bpkYktd4UN5DtUS45MMNdWYr7c-OG7DHOX21QXG4LMUA@mail.gmail.com> <4D587C0C-EB5F-4A58-A0AE-D45E43F432CD@gmail.com> <CAH+w=7bQLq43JChP7PmaqT_wHMwgs4Nk_-0grrtQXEhQJcfrbA@mail.gmail.com> <CAH+w=7ZCzG-BGZuU-rLoZJX=3zcA74NK+TNVDP-CWF-9b-BfrA@mail.gmail.com> <AEC92FEA-6216-4952-818E-9DC7C584698A@gmail.com> <20210421212717.GE21343@tarpaulin.shahaf.local2> <CAH+w=7bFfZucFRj9OZvzTnvxd+QUW7tZHAJiMLi+O0PNjz=wyA@mail.gmail.com> <214AC3E9-FFA5-4F39-A918-562682FE3A3B@gmail.com> <CAH+w=7ZSWhyogP=rn_O40Lc96jTnM4rAKkHaXLn5iOsS7F76Vg@mail.gmail.com> <CAHLkEDspzutwPTAqC7HqdAJDqF0FncsWH6NsHk5Z=bt+Jww8vg@mail.gmail.com> <CAH+w=7ZhNyZypwtMvgBcCkUwCLRzB1+XtccdYG14A1zVJsSTrg@mail.gmail.com> <CAH+w=7YTPm_5=8cPSydgte_Ti7UaihR4s+fOz0H97_4dZwCeiw@mail.gmail.com> <CAHLkEDu4Ac_gRWCuZs24GW84djZ1t7tyVKroAxXrtvWBqUVWqg@mail.gmail.com> <CAH+w=7ZDorYi2C+0ycysL=99nh_6Mw865H4kB6ZYaHmMZr9tNA@mail.gmail.com> <CAHLkEDtgMYYVdtHBiPDYbhdhwRH9Ha3T1ix+G_q_=-miNgo=PA@mail.gmail.com>
On Tue, Apr 27, 2021 at 3:46 AM Marlon Richert <marlon.richert@xxxxxxxxx> wrote:
> On Tue, Apr 27, 2021 at 12:40 AM Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > Anyway, no, there's no way to abort the current ZLE without $?
> > becoming nonzero.
I dug around to refresh my memory on this. The important detail is
that the PS1/PS2 prompts represent ZLE doing a handshake with the
input parser+lexer. The only way to get back to the PS1 prompt is to
get the parser to abandon its current state, and the only generalized
way to do that is to cause the lexer to return an error, so send-break
simulates the shell having received a keyboard interrupt. That aborts
the lexer, which aborts the parser, and the top-level state is
restored. $? represents the interrupt (you can tell a real interrupt
from a simulated one because $? = 130 in the signal case).
BTW, a possible bug with this is that $ZLE_LINE_ABORTED is not
assigned when there is a simulated interrupt.
> In my patch, the last thing done before the widget exits is to set
> $BUFFER and call zle .accept-line. The only return value the user will
> see in that case is that of the executed command; not that of
> .push-line-or-edit. I still prefer that version. Are there drawbacks
> to that approach?
The main drawback is the complexity involved in
creating/installing/disposing a hook function that modifies the zle
startup. Seeing the exit status of the executed command via %? in the
prompt doesn't "feel" important enough to me to justify the extra
It's also the case that your solution takes two different code paths
in the calling widget depending on $CONTEXT -- the widget continues
past execute-command in the PS1 (or the $? = 75) case, but is aborted
in the PS2 case. My solution consistently stops the calling widget if
the command is executed. The documentation will need to account for
whichever approach is chosen.
Perhaps execute-command could set a variable with the exit status of
the command, and then a user for whom it is important to see that
status in the prompt could implement $PS1 in such a way as to show it
in place of %? (and then clear it, perhaps in preexec).
Messages sorted by: