Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Tip of the day: restoring an aborted command-line
- X-seq: zsh-users 20301
- From: Philippe Troin <phil@xxxxxxxx>
- To: zzapper <david@xxxxxxxxxxxxxx>
- Subject: Re: Tip of the day: restoring an aborted command-line
- Date: Thu, 02 Jul 2015 16:11:13 -0700
- Cc: zsh-users@xxxxxxx
- In-reply-to: <XnsA4CBE4DD846E3davidrayninfocouk@80.91.229.13>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <30469.1435788779@thecus.kiddle.eu> <XnsA4CBE4DD846E3davidrayninfocouk@80.91.229.13>
On Thu, 2015-07-02 at 21:29 +0000, zzapper wrote:
> Oliver Kiddle <okiddle@xxxxxxxxxxx> wrote in
> news:30469.1435788779@xxxxxxxxxxxxxxxx:
>
> > When you abort a command-line with Ctrl-C or whatever, the Zsh line
> > editor sets $ZLE_LINE_ABORTED to the contents of the command-line
> > before it was aborted. Sometimes you might want to recover the aborted
> > line and you could bind a dedicated key to that purpose. The following
>
> >
> > zle-line-init () {
> > if [[ -n $ZLE_LINE_ABORTED ]]; then
> > local savebuf="$BUFFER" savecur="$CURSOR"
> > BUFFER="$ZLE_LINE_ABORTED"
> > CURSOR="$#BUFFER"
> > zle split-undo
> > BUFFER="$savebuf" CURSOR="$savecur"
> > fi
> > }
>
> > Oliver
> is $ZLE_LINE_ABORTED dependent on any autoload? as i have it on cygwin
> but not on centos (both 5.08)
It shouldn't.
I'd like to propose the following enhancement:
zle-line-init () {
if [[ -n $ZLE_LINE_ABORTED ]]; then
_last_aborted_line=$ZLE_LINE_ABORTED
fi
if [[ -n $_last_aborted_line ]]
then
local savebuf="$BUFFER" savecur="$CURSOR"
BUFFER="$_last_aborted_line"
CURSOR="$#BUFFER"
zle split-undo
BUFFER="$savebuf" CURSOR="$savecur"
fi
}
zle -N zle-line-init
zle-line-finish() {
unset _last_aborted_line
}
zle -N zle-line-finish
Now this handle the case when you press Ctrl-C multiple times in a row.
Eg:
zsh% foo=^C
zsh% ^C
zsh% ^C
zsh% <undo>
zsh% foo=
Phil.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author