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

Re: Colored-character displayed on CTRL-C ?

On Sep 23,  5:37pm, Larry Schrof wrote:
} Recent versions of bash have this very nifty feature where, when you
} hit CTRL-C to terminate a command line and get a new prompt on a new
} line, something like ^C with a yellow background is displayed to help
} remind you that the command is not actually executed.

This should do it for you:

    autoload -Uz colors
    handle-interrupt() {
      print -n "$bg_bold[yellow]${(V)KEYS:-^C}$reset_color"
      zle -I && zle .kill-buffer
    zle -N handle-interrupt
    TRAPINT() { zle && zle handle-interrupt }

You might also want to

    bindkey ^G handle-interrupt

to replace the built-in binding for send-break, but this behaves a bit
differently than send-break in some situations so use with caution.

The use of kill-buffer also pushes the line onto the kill ring, so you
can get it back with ^Y after interrupting it.  Perhaps that's a feature.

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