mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-12-29 04:23:26 +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
|
||||
# of the "fast" command.
|
||||
|
||||
# To solve this, we set a flag `PREEXEC_READY` when the prompt is drawn, and only
|
||||
# start the timer if this flag is present. That way, timing is for the entire command,
|
||||
# and not just a portion of it.
|
||||
# To solve this, we set a flag `STARSHIP_PREEXEC_READY` when the prompt is
|
||||
# drawn, and only start the timer if this flag is present. That way, timing is
|
||||
# for the entire command, and not just a portion of it.
|
||||
|
||||
# Will be run before *every* command (even ones in pipes!)
|
||||
starship_preexec() {
|
||||
@ -18,8 +18,8 @@ starship_preexec() {
|
||||
local PREV_LAST_ARG=$1
|
||||
|
||||
# Avoid restarting the timer for commands in the same pipeline
|
||||
if [ "$PREEXEC_READY" = "true" ]; then
|
||||
PREEXEC_READY=false
|
||||
if [ "$STARSHIP_PREEXEC_READY" = "true" ]; then
|
||||
STARSHIP_PREEXEC_READY=false
|
||||
STARSHIP_START_TIME=$(::STARSHIP:: time)
|
||||
fi
|
||||
|
||||
@ -30,7 +30,7 @@ starship_preexec() {
|
||||
starship_precmd() {
|
||||
local NUM_JOBS
|
||||
# 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
|
||||
# like z/autojump, which background certain jobs, do not cause spurious background jobs
|
||||
@ -46,12 +46,12 @@ starship_precmd() {
|
||||
if [[ $STARSHIP_START_TIME ]]; then
|
||||
STARSHIP_END_TIME=$(::STARSHIP:: 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
|
||||
else
|
||||
PS1="$(::STARSHIP:: prompt --status=$STATUS --jobs="$NUM_JOBS")"
|
||||
PS1="$(::STARSHIP:: prompt --status=$STARSHIP_CMD_STATUS --jobs="$NUM_JOBS")"
|
||||
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,
|
||||
|
@ -13,13 +13,13 @@ starship_render() {
|
||||
# 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
|
||||
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
|
||||
starship_precmd() {
|
||||
# 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
|
||||
# previous duration
|
||||
|
Loading…
Reference in New Issue
Block a user