Change ZSH init to use jobstates for num jobs (#252)

This commit is contained in:
Kevin Song 2019-09-03 22:44:44 -05:00 committed by Matan Kushner
parent f2f7815960
commit 6db0e20585
1 changed files with 7 additions and 2 deletions

View File

@ -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(){