diff options
author | Rich Lafferty <rlafferty@pagerduty.com> | 2021-01-31 16:56:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-31 22:56:06 +0100 |
commit | 3127a9aa871342e295e4fc83c01b6bd04a4957ed (patch) | |
tree | d7a2da3a2464351684e9b023394b783b00351af7 | |
parent | 383d2df580dab30c56e9589b4033b7e2f867bc1d (diff) |
fix(bash): Count jobs with for loop to fix MacOS count issue (#2250)
In #1897 we replaced a 'wc -l' with a bash-native job counter, but
subsequently discovered that bash on MacOS folds '<<<' output into
a single line, preventing line counting.
A for loop works around that problem, is still bash-native, and works
on Linux as well.
While we're at it, also removed the need for command substitution and
an echo by doing the work directly on NUM_JOBS.
Fixes #2241.
-rw-r--r-- | src/init/starship.bash | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/init/starship.bash b/src/init/starship.bash index 055335270..14902be12 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -31,11 +31,11 @@ starship_precmd() { # Save the status, because commands in this pipeline will change $? STARSHIP_CMD_STATUS=$? - local NUM_JOBS + local NUM_JOBS=0 # Evaluate the number of jobs before running the preseved prompt command, so that tools # like z/autojump, which background certain jobs, do not cause spurious background jobs - # to be displayed by starship. Also avoids forking to run `wc`, slightly improving perf - NUM_JOBS=$(n=0; while read line; do [[ $line ]] && n=$((n+1));done <<< $(jobs -p) ; echo $n) + # to be displayed by starship. Also avoids forking to run `wc`, slightly improving perf. + for job in $(jobs -p); do [[ $job ]] && ((NUM_JOBS++)); done # Run the bash precmd function, if it's set. If not set, evaluates to no-op "${starship_precmd_user_func-:}" |