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

Re: Append cancelled commands to history



On Sat, Mar 20, 2010, Bart Schaefer wrote about "Re: Append cancelled commands to history":
> > I thought this would be simple - just replace the print line with
> > 	print -s -r -- "$PREBUFFER$BUFFER"
> 
> Hmm.  When I use TRAPINT, $PREBUFFER is always empty.
> 
> torch% print $ZSH_VERSION $ZSH_PATCHLEVEL 
> 4.3.10-dev-1 1.4940

Thanks for the explanations. For me, $PREBUFFER does work:

$ print $ZSH_VERSION $ZSH_PATCHLEVEL
4.3.10 1.4705
$ cat /etc/redhat-release; rpm -qf =zsh
Fedora release 12 (Constantine)
zsh-4.3.10-4.fc12.x86_64

$ functions TRAPINT
TRAPINT () {
        zle && [[ $HISTNO -eq $HISTCMD ]] && print -s -r -- "$PREBUFFER$BUFFER"
        echo "prebuffer: '$PREBUFFER'"
        return $1
}

$ for i in *
for> do
for> echo<INTERRUPT>prebuffer: 'for i in *
do
'

$

But the problem I have now is that when I now go up in the history, the
last command I see is

	for i in *
	do

which is what standard zsh saved - without the last partial line - and when I
go up another command in history I see

	for i in *
	do
	echo

which is what my code saved. I wished there was a way not to save that
shorter version, with only the accepted lines.

Of course, it's not so terrible as it is - I just wondered if there's a
way to do it better. Usually when I interrupt a multi-line command entry,
it's not because I'm not pleased with the last line I typed (if this was
the case, I could have just backspaced...), but rather, I'm not pleased
with the whole thing. So I want to save the whole thing (including the
last line I'm editing), and go to edit it later if I wish.


-- 
Nadav Har'El                        |        Monday, Mar 22 2010, 7 Nisan 5770
nyh@xxxxxxxxxxxxxxxxxxx             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Why do we drive on a parkway and park on
http://nadav.harel.org.il           |a driveway?



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