summaryrefslogtreecommitdiffstats
path: root/src/init.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.rs')
-rw-r--r--src/init.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/init.rs b/src/init.rs
index 9bb7ad9b1..41aaac046 100644
--- a/src/init.rs
+++ b/src/init.rs
@@ -208,19 +208,24 @@ ever drawn once (for the prompt immediately after it is run).
*/
const ZSH_INIT: &str = r##"
+zmodload zsh/parameter # Needed to access jobstates variable for NUM_JOBS
+
# Will be run before every prompt draw
starship_precmd() {
# Save the status, because commands in this pipeline will change $?
STATUS=$?
+ # Use length of jobstates array as number of jobs. Expansion fails inside
+ # quotes so we set it here and then use the value later on.
+ NUM_JOBS=$#jobstates
# Compute cmd_duration, if we have a time to consume
if [[ ! -z "${STARSHIP_START_TIME+1}" ]]; then
STARSHIP_END_TIME="$(date +%s)"
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
- PROMPT="$(## STARSHIP ## prompt --status=$STATUS --cmd-duration=$STARSHIP_DURATION --jobs="$(jobs | wc -l)")"
+ PROMPT="$(## STARSHIP ## prompt --status=$STATUS --cmd-duration=$STARSHIP_DURATION --jobs="$NUM_JOBS")"
unset STARSHIP_START_TIME
else
- PROMPT="$(## STARSHIP ## prompt --status=$STATUS --jobs="$(jobs | wc -l)")"
+ PROMPT="$(## STARSHIP ## prompt --status=$STATUS --jobs="$NUM_JOBS")"
fi
}
starship_preexec(){