From 6db0e205856db7f5ebe417c2e3753d699c212dd9 Mon Sep 17 00:00:00 2001 From: Kevin Song Date: Tue, 3 Sep 2019 22:44:44 -0500 Subject: Change ZSH init to use jobstates for num jobs (#252) --- src/init.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') 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(){ -- cgit v1.2.3