diff options
author | Kevin Song <chipbuster@users.noreply.github.com> | 2019-09-03 22:44:44 -0500 |
---|---|---|
committer | Matan Kushner <hello@matchai.me> | 2019-09-03 23:44:44 -0400 |
commit | 6db0e205856db7f5ebe417c2e3753d699c212dd9 (patch) | |
tree | c52075e059d4b7cedb0b7d8d8864c7e2127ee743 | |
parent | f2f7815960867f37faf3cc65f775773ed1c5e143 (diff) |
Change ZSH init to use jobstates for num jobs (#252)
-rw-r--r-- | src/init.rs | 9 |
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(){ |