3

I’ve noticed that under Bash 4.4 (but not Bash 3.2), if I’m entering a command and then type Ctrl-C to abort, the shell inserts the text ^C at the cursor before displaying the new prompt line. Is there a way to configure zsh so that it does the same thing?

(This is sort of the opposite of this question, which is asking how to turn off this behavior, although that question is about Bash. This answer to another question shows how to get zle to highlight special characters when they appear in a command line, but I’m not inserting a literal 0x03 byte into the command line; I’m trying to get some text to appear when I type a control character.)

0

1 Answer 1

1

This works at least in simple cases:

precmd () {
  trap 'print -P "%B%F{red}^C%f%b"; zle send-break' INT
}
preexec () {
  trap - INT
}

I haven't explored how this works in “difficult” cases, such as a completion function that's taking too long.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .