#1 zsh: you have running jobs.



我定义了一个 gitg 的快捷方式:

function _new_gitg () {
    # alias g='gitg --all >/dev/null 2>&1 &'  # 覆盖 g=git
    if [ -z "$1" ]; then
        nohup gitg --all >/dev/null 2>&1 &!
    else
        nohup gitg -s $1 >/dev/null 2>&1 &!
    fi
}
alias g='_new_gitg'

但是每次退出 shell 会有提示:zsh: you have running jobs.

我就加上 nohup,以为不会有提示,但提示依旧(不过强制退出也不会关闭 gitg 就是了)。

在 SO 上搜到相同问题,这个答复就可以很好的解决我的问题:

If you want to not see that message, simply pass the job id to disown, like so:

> disown %1
> ```
> Or, start the job with &! (zsh-specific trick):
> ```sh
> nohup ./my_script.sh &!
> ```

```sh
function _new_gitg () {
    if [ -z "$1" ]; then
        nohup gitg --all >/dev/null 2>&1 &!
    else
        nohup gitg -s $1 >/dev/null 2>&1 &!
    fi
}
alias g='_new_gitg'

经过测试,这个技巧在 bash 5.1.4 下也有效。