diff options
author | Bjørn Forsman <bjorn.forsman@gmail.com> | 2020-12-19 12:04:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 12:04:15 +0100 |
commit | f17556d3898363655feb8735bb21de9fa4f28528 (patch) | |
tree | 5c21082b9765d2443fd38dd27c269e862bc2a911 | |
parent | 9a2355c164206105ce1df8d35acc90a4129d3ebe (diff) |
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.)
-rw-r--r-- | src/init/starship.bash | 18 | ||||
-rw-r--r-- | src/init/starship.zsh | 4 |
2 files changed, 11 insertions, 11 deletions
diff --git a/src/init/starship.bash b/src/init/starship.bash index a7e17045a..2d1eb84cb 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -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, diff --git a/src/init/starship.zsh b/src/init/starship.zsh index 0c25121a7..07afe7cc1 100644 --- a/src/init/starship.zsh +++ b/src/init/starship.zsh @@ -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 |