From b4195a0dfe5310287e2c53ac1474eb892e3719e8 Mon Sep 17 00:00:00 2001 From: Gek Siong Low Date: Fri, 8 May 2020 18:19:43 +0800 Subject: [PATCH] Fix 'can't manipulate jobs in subshell' error in zsh --- gitprompt.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gitprompt.sh b/gitprompt.sh index 312ba9f..75d8cee 100755 --- a/gitprompt.sh +++ b/gitprompt.sh @@ -9,7 +9,15 @@ function async_run() { }& } -function set_git_prompt_dir() { +function async_run_zsh() { + { + eval "$@" &> /dev/null + }&! +} + + +function git_prompt_dir() { + # assume the gitstatus.sh is in the same directory as this script # code thanks to http://stackoverflow.com/questions/59895 if [ -z "$__GIT_PROMPT_DIR" ]; then __GIT_PROMPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) @@ -441,8 +449,12 @@ function checkUpstream() { then if [[ -n $(git remote show) ]]; then ( - async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet" - disown -h + if [ -n $ZSH_VERSION ]; then + async_run_zsh "GIT_TERMINAL_PROMPT=0 git fetch --quiet" + else + async_run "GIT_TERMINAL_PROMPT=0 git fetch --quiet" + disown -h + fi ) fi fi