fix(bash): Clear out completed jobs before counting NUM_JOBS (#5253)

Clear out completed jobs before counting NUM_JOBS
This commit is contained in:
Ajeet D'Souza 2023-06-17 17:36:35 +05:30 committed by GitHub
parent 0dfca07255
commit 0a05b5ca8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,18 @@ starship_precmd() {
STARSHIP_PIPE_STATUS=(${BP_PIPESTATUS[@]})
fi
# Due to a bug in certain Bash versions, any external process launched
# inside $PROMPT_COMMAND will be reported by `jobs` as a background job:
#
# [1] 42135 Done /bin/echo
#
# This is a workaround - we run `jobs` once to clear out any completed jobs
# first, and then we run it again and count the number of jobs.
#
# More context: https://github.com/starship/starship/issues/5159
# Original bug: https://lists.gnu.org/archive/html/bug-bash/2022-07/msg00117.html
jobs &>/dev/null
local NUM_JOBS=0
# Evaluate the number of jobs before running the preserved prompt command, so that tools
# like z/autojump, which background certain jobs, do not cause spurious background jobs