4 ms·
I have the following in my .zshrc that I'm sure I copied from somewhere. It allows the use of Ctrl-z to also resume programs runnings in the background instead
by michaelmior 4y ago
I have the following in my .zshrc that I'm sure I copied from somewhere. It allows the use of Ctrl-z to also resume programs runnings in the background instead of manually typing fg.
# Allow Ctrl-z to toggle between suspend and resume
function Resume {
fg
zle push-input
BUFFER=""
zle accept-line
}
zle -N Resume
bindkey "^Z" Resume
- mtlmtlmtlmtl 4y agoThis is really neat! Threw it in my .zshrc right away. Thank you sir.
- _huayra_ 4y agos/fg/bg/ ?
- michaelmior 4y agoNo. When a program is running in the shell, the default behavior is for Ctrl-z to suspend the program. Nothing needs to be done for that to happen. This snippet runs `fg` when you're back in the shell and press Ctrl-z. That said, if you wanted to continue running in the background with `bg`, you could make that substitution to allow you to double tap Ctrl-z to do so.
- _huayra_ 4y agoOh wow I totally misunderstood this snippet; I thought it was in fact the opposite (i.e. a shortcut to send a job to the background). Toggling back to the foreground is even better with the same shortcut! Neat!
- jopython 4y agoSolution for bash anyone? Saw this in the internets if [[ $- == i ]]; then stty susp undef bind '"\C-z":" fg\015"' fi
- michaelmior 4y agoFWIW, after a quick Google search, I think this may have been the original source. https://www.reddit.com/r/vim/comments/9bm3x0/ctrlz_binding/ https://www.reddit.com/r/vim/comments/9bm3x0/ctrlz_binding/
- citruscomputing 4y agoHere's how to do it in fish: bind \cz 'fg 2>/dev/null; commandline -f repaint' from: https://github.com/fish-shell/fish-shell/issues/7152#issuecomment-663575001 https://github.com/fish-shell/fish-shell/issues/7152#issueco...