Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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


This is really neat!

Threw it in my .zshrc right away. Thank you sir.


Here'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#issueco...


FWIW, after a quick Google search, I think this may have been the original source.

https://www.reddit.com/r/vim/comments/9bm3x0/ctrlz_binding/


Solution for bash anyone?

Saw this in the internets

if [[ $- == i ]]; then

  stty susp undef

  bind '"\C-z":" fg\015"'
fi


s/fg/bg/ ?


No. 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.


Oh 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!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: