mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-01 09:13:54 +00:00
feat(init): prefix STATUS and PREEXEC_READY shell vars with STARSHIP_ (#1710)
I was surprised to see these (unprefixed) variables being set in my shell. I think it's better to have them in the STARSHIP_ "namespace". (Actually, STATUS got the new name STARSHIP_CMD_STATUS.)
This commit is contained in:
parent
9a2355c164
commit
f17556d389
@ -8,9 +8,9 @@
|
|||||||
# data for commands like `slow | slow | fast`, since the timer starts at the start
|
# data for commands like `slow | slow | fast`, since the timer starts at the start
|
||||||
# of the "fast" command.
|
# of the "fast" command.
|
||||||
|
|
||||||
# To solve this, we set a flag `PREEXEC_READY` when the prompt is drawn, and only
|
# To solve this, we set a flag `STARSHIP_PREEXEC_READY` when the prompt is
|
||||||
# start the timer if this flag is present. That way, timing is for the entire command,
|
# drawn, and only start the timer if this flag is present. That way, timing is
|
||||||
# and not just a portion of it.
|
# for the entire command, and not just a portion of it.
|
||||||
|
|
||||||
# Will be run before *every* command (even ones in pipes!)
|
# Will be run before *every* command (even ones in pipes!)
|
||||||
starship_preexec() {
|
starship_preexec() {
|
||||||
@ -18,8 +18,8 @@ starship_preexec() {
|
|||||||
local PREV_LAST_ARG=$1
|
local PREV_LAST_ARG=$1
|
||||||
|
|
||||||
# Avoid restarting the timer for commands in the same pipeline
|
# Avoid restarting the timer for commands in the same pipeline
|
||||||
if [ "$PREEXEC_READY" = "true" ]; then
|
if [ "$STARSHIP_PREEXEC_READY" = "true" ]; then
|
||||||
PREEXEC_READY=false
|
STARSHIP_PREEXEC_READY=false
|
||||||
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ starship_preexec() {
|
|||||||
starship_precmd() {
|
starship_precmd() {
|
||||||
local NUM_JOBS
|
local NUM_JOBS
|
||||||
# Save the status, because commands in this pipeline will change $?
|
# Save the status, because commands in this pipeline will change $?
|
||||||
STATUS=$?
|
STARSHIP_CMD_STATUS=$?
|
||||||
|
|
||||||
# Evaluate the number of jobs before running the preseved prompt command, so that tools
|
# Evaluate the number of jobs before running the preseved prompt command, so that tools
|
||||||
# like z/autojump, which background certain jobs, do not cause spurious background jobs
|
# like z/autojump, which background certain jobs, do not cause spurious background jobs
|
||||||
@ -46,12 +46,12 @@ starship_precmd() {
|
|||||||
if [[ $STARSHIP_START_TIME ]]; then
|
if [[ $STARSHIP_START_TIME ]]; then
|
||||||
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
||||||
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
|
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
|
||||||
PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)"
|
PS1="$(::STARSHIP:: prompt --status=$STARSHIP_CMD_STATUS --jobs="$NUM_JOBS" --cmd-duration=$STARSHIP_DURATION)"
|
||||||
unset STARSHIP_START_TIME
|
unset STARSHIP_START_TIME
|
||||||
else
|
else
|
||||||
PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$NUM_JOBS")"
|
PS1="$(::STARSHIP:: prompt --status=$STARSHIP_CMD_STATUS --jobs="$NUM_JOBS")"
|
||||||
fi
|
fi
|
||||||
PREEXEC_READY=true # Signal that we can safely restart the timer
|
STARSHIP_PREEXEC_READY=true # Signal that we can safely restart the timer
|
||||||
}
|
}
|
||||||
|
|
||||||
# If the user appears to be using https://github.com/rcaloras/bash-preexec,
|
# If the user appears to be using https://github.com/rcaloras/bash-preexec,
|
||||||
|
@ -13,13 +13,13 @@ starship_render() {
|
|||||||
# Use length of jobstates array as number of jobs. Expansion fails inside
|
# 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.
|
# quotes so we set it here and then use the value later on.
|
||||||
NUM_JOBS=$#jobstates
|
NUM_JOBS=$#jobstates
|
||||||
PROMPT="$(::STARSHIP:: prompt --keymap="${KEYMAP-}" --status=$STATUS --cmd-duration=${STARSHIP_DURATION-} --jobs="$NUM_JOBS")"
|
PROMPT="$(::STARSHIP:: prompt --keymap="${KEYMAP-}" --status=$STARSHIP_CMD_STATUS --cmd-duration=${STARSHIP_DURATION-} --jobs="$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=$?
|
STARSHIP_CMD_STATUS=$?
|
||||||
|
|
||||||
# Compute cmd_duration, if we have a time to consume, otherwise clear the
|
# Compute cmd_duration, if we have a time to consume, otherwise clear the
|
||||||
# previous duration
|
# previous duration
|
||||||
|
Loading…
Reference in New Issue
Block a user