summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Seré <felipesere@gmail.com>2021-04-29 15:16:25 +0100
committerGitHub <noreply@github.com>2021-04-29 16:16:25 +0200
commit0e23526f5fc91af127589bbf53fe620196022445 (patch)
tree41ab1e6d84fa7510e86a3f56f69beeac698f5d96
parent00e64ecb7452819c0e35403f33e56dc36af18b8e (diff)
fix(zsh): Reverts changes to background jobs retaining improvements around START_TIME (#2638)
* Revert "fix(zsh): Set PROMPT just once (#2428)" This reverts commit 6fd7d7b5010c28d0557e4ff562187098abaa3bc6. * Reintroduce fixes around START_TIME * Bring back disabling virtualenv * Expand the jobstates before passing the number to starship Credit goes to @vladimyr
-rw-r--r--src/init/starship.zsh14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/init/starship.zsh b/src/init/starship.zsh
index eb5ebce24..b5e936c4a 100644
--- a/src/init/starship.zsh
+++ b/src/init/starship.zsh
@@ -7,6 +7,8 @@
# after drawing the prompt. This ensures that the timing for one command is only
# ever drawn once (for the prompt immediately after it is run).
+zmodload zsh/parameter # Needed to access jobstates variable for STARSHIP_JOBS_COUNT
+
# Defines a function `__starship_get_time` that sets the time since epoch in millis in STARSHIP_CAPTURED_TIME.
if [[ $ZSH_VERSION == ([1-4]*) ]]; then
# ZSH <= 5; Does not have a built-in variable so we will rely on Starship's inbuilt time function.
@@ -34,6 +36,10 @@ starship_precmd() {
else
unset STARSHIP_DURATION
fi
+
+ # 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.
+ STARSHIP_JOBS_COUNT=${#jobstates}
}
starship_preexec() {
__starship_get_time && STARSHIP_START_TIME=$STARSHIP_CAPTURED_TIME
@@ -63,12 +69,12 @@ starship_zle-keymap-select() {
local existing_keymap_select_fn=$widgets[zle-keymap-select];
# zle-keymap-select is a special widget so it'll be "user:fnName" or nothing. Let's get fnName only.
existing_keymap_select_fn=${existing_keymap_select_fn//user:};
-if [[ -z ${existing_keymap_select_fn} ]]; then
+if [[ -z $existing_keymap_select_fn ]]; then
zle -N zle-keymap-select starship_zle-keymap-select;
else
# Define a wrapper fn to call the original widget fn and then Starship's.
starship_zle-keymap-select-wrapped() {
- ${existing_keymap_select_fn} "$@";
+ $existing_keymap_select_fn "$@";
starship_zle-keymap-select "$@";
}
zle -N zle-keymap-select starship_zle-keymap-select-wrapped;
@@ -85,5 +91,5 @@ export STARSHIP_SESSION_KEY=${STARSHIP_SESSION_KEY:0:16}; # Trim to 16-digits if
VIRTUAL_ENV_DISABLE_PROMPT=1
-setopt prompt{percent,subst}
-PROMPT='$(::STARSHIP:: prompt --keymap=${KEYMAP} --status=${STARSHIP_CMD_STATUS} --cmd-duration=${STARSHIP_DURATION} --jobs=%j)'
+setopt promptsubst
+PROMPT='$(::STARSHIP:: prompt --keymap="$KEYMAP" --status="$STARSHIP_CMD_STATUS" --cmd-duration="$STARSHIP_DURATION" --jobs="$STARSHIP_JOBS_COUNT")'