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

Re: Add ^C'd commands to history?

On Dec 16,  8:20pm, Jeremy M. Dolan wrote:
} Many times I type out a long command, maybe iptables or something,
} then realize I need to do $X first, so I have to ^C the command.

As Stephen Rueger has already pointed out, this is exactly what push-line
is for.  (Actually I prefer push-line-or-edit for the case of multi-line

The difficulty with binding anything like this to ^C is that (normally)
the tty driver interprets ^C before zsh ever sees it, and sends an INT
signal.  Zsh doesn't know where the INT signal came from, and the ZLE
module can't presume to handle non-keyboard interrupts, so in order to
have the line editor do something on ^C you have to use the stty command
to disable the driver interpretation of that keystroke.  That can be a
problem if you also want to use it to send an actual interrupt.

So my recommendation is to get used to typing something else when you
want a line stored in the history, and use ^C for what it was meant for.

However, if you really want to hang yourself, here is the rope:

    function push-to-history {
	print -s "$BUFFER"
	zle send-break
    zle -N push-to-history
    bindkey '^C' push-to-history
    export STTY='intr ^C'
    ttyctl -u
    stty intr ''
    ttyctl -f

Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   

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