How to show a caret-C in canceled command line in zsh, like bash does?
You can define a trap for SIGINT (triggered by CTRL-C
), which will print ^C
(or any other text you would like):
TRAPINT() {
print -n "^C"
return $(( 128 + $1 ))
}
This example is taken from man zshmisc
. The return command has the following background:
Programs terminated by uncaught signals typically return the status 128 plus the signal number. Hence the [above code] causes the handler for SIGINT to print a message, then mimic the usual effect of the signal.