Last active
August 29, 2015 14:21
-
-
Save izabera/6a1e58b22e33a496457e to your computer and use it in GitHub Desktop.
map C-c and C-z in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# map C-c to kill-whole-line like in fish and C-z to fg | |
saved_stty=$(command stty -g) | |
stty () { | |
local status | |
command stty "$@" | |
status=$? | |
saved_stty=$(command stty -g) | |
return "$status" | |
} | |
# use a function to avoid calling the DEBUG trap more than once | |
PROMPT_COMMAND=prompt_command | |
prompt_command () { | |
# other commands here | |
undefC-cC-z | |
} | |
# use the prompt flag to avoid calling stty several times | |
# in the DEBUG trap with compound commands | |
undefC-cC-z () { | |
(( ! prompt_flag )) && command stty intr undef susp undef | |
prompt_flag=1 | |
} | |
resetC-cC-z () { | |
(( prompt_flag )) && command stty "$saved_stty" | |
prompt_flag=0 | |
} | |
bind '\C-z: "\C-cfg\C-m"' '\C-c: kill-whole-line' | |
bind -m vi-command '\C-z: "\C-cifg\C-m"' | |
bind -m vi-move '\C-z: "\C-cifg\C-m"' | |
# save the last arg in __ then restore it | |
trap '__=$_; resetC-cC-z; : "$__"' DEBUG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment