Ctrl-z suspends the foreground process, but when there is nothing in the foreground it has no effect. I want to overload ctrl-z so when there is nothing in the foreground it brings the most recently suspended process back. This way, hitting ctrl-z toggles the foreground process. How would you do this?

BTW, I use zsh, but anything that works in bash should work too. I'm in terminal on OS X

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted
ctrlz () {
  if [[ $#BUFFER -eq 0 ]]; then
    fg
    zle redisplay
  else
    zle push-input
  fi
}
zle -N ctrlz
bindkey '^Z' ctrlz
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.