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

Re: Append cancelled commands to history



On Mon, Jul 06, 2009, Nadav Har'El wrote about "Re: Append cancelled commands to history":
> > 		zle && print -s -- $BUFFER
> 
> I wonder, isn't "-r" also wise to add, otherwise if you have escape sequences
> like "\n", "\c", etc., in your command line, they will be modified by the
> print command?

I added another trick: It annoyed me that if I go back in history and change
my mind, pressing interrupt now will save the whatever command I moved back
to again in the front of the history. I wanted the interrupt key to only save
a new command.
So I added a check for this, using the HISTNO and HISTCMD variables we have
access to: If those are equal, we're editing a new command, but if they're
not, we're on an old command from the history:

# When a line is killed, put it in the history anyway in case we want to
# return to it
TRAPINT() {
        # Store the current buffer in the history.
        zle && 
        [[ $HISTNO -eq $HISTCMD ]] && # only if we're not back in the history
        print -s -r -- $BUFFER

        # Return the default exit code so zsh aborts the current command.
        return $1
}


-- 
Nadav Har'El                        |      Monday, Jul  6 2009, 15 Tammuz 5769
nyh@xxxxxxxxxxxxxxxxxxx             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Ways to Relieve Stress #10: Make up a
http://nadav.harel.org.il           |language and ask people for directions.



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