Skip to content

Commit

Permalink
fix(bash): Clear out completed jobs before counting NUM_JOBS (#5253)
Browse files Browse the repository at this point in the history
Clear out completed jobs before counting NUM_JOBS
  • Loading branch information
ajeetdsouza committed Jun 17, 2023
1 parent 0dfca07 commit 0a05b5c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/init/starship.bash
Expand Up @@ -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
Expand Down

0 comments on commit 0a05b5c

Please sign in to comment.