mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-26 11:37:32 +00:00
Change ZSH init to use jobstates for num jobs (#252)
This commit is contained in:
parent
f2f7815960
commit
6db0e20585
@ -208,19 +208,24 @@ ever drawn once (for the prompt immediately after it is run).
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const ZSH_INIT: &str = r##"
|
const ZSH_INIT: &str = r##"
|
||||||
|
zmodload zsh/parameter # Needed to access jobstates variable for NUM_JOBS
|
||||||
|
|
||||||
# Will be run before every prompt draw
|
# Will be run before every prompt draw
|
||||||
starship_precmd() {
|
starship_precmd() {
|
||||||
# Save the status, because commands in this pipeline will change $?
|
# Save the status, because commands in this pipeline will change $?
|
||||||
STATUS=$?
|
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
|
# Compute cmd_duration, if we have a time to consume
|
||||||
if [[ ! -z "${STARSHIP_START_TIME+1}" ]]; then
|
if [[ ! -z "${STARSHIP_START_TIME+1}" ]]; then
|
||||||
STARSHIP_END_TIME="$(date +%s)"
|
STARSHIP_END_TIME="$(date +%s)"
|
||||||
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
|
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
|
unset STARSHIP_START_TIME
|
||||||
else
|
else
|
||||||
PROMPT="$(## STARSHIP ## prompt --status=$STATUS --jobs="$(jobs | wc -l)")"
|
PROMPT="$(## STARSHIP ## prompt --status=$STATUS --jobs="$NUM_JOBS")"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
starship_preexec(){
|
starship_preexec(){
|
||||||
|
Loading…
Reference in New Issue
Block a user