From 0a05b5ca8b7f147ead6d575297ef9f34191193af Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Sat, 17 Jun 2023 17:36:35 +0530 Subject: [PATCH] fix(bash): Clear out completed jobs before counting NUM_JOBS (#5253) Clear out completed jobs before counting NUM_JOBS --- src/init/starship.bash | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/init/starship.bash b/src/init/starship.bash index 04d3be96..370e0b27 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -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