In zsh, how can I more quickly disown the foreground process

background-processdisownsignalszsh

My method for disowning the foreground process takes too much effort.

Suppose I have a process in zsh's foreground. I want to disown it, so I can close the shell without the process being sent a SIGHUP.

At the moment, I start with Ctrl+z to background and pause the process, then

$ disown
disown: warning: job is suspended, use `kill -CONT -32240' to resume
$ kill -CONT -32240
$

then I can close the terminal.

How can I automate that? Ideally, I'd like to be able to press Ctrl+j or something to immediately disown the running process. Or second best, I'd want to be able to run a single command to both disown and SIGCONT the process once it's suspended.

Best Answer

Having a global keybind to disown the foreground process is impossible: Keystrokes are received by the foreground process, not by the shell. You need to first suspend it with Ctrl+z if you want to disown it.

However, turns out there's a zsh option to speed up disowning then continuing: With setopt AUTO_CONTINUE, disown will automatically also send SIGCONT.

So you can get it down to C-z disown.

Related Question