1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

fix(zsh): Reverts changes to background jobs retaining improvements around START_TIME (#2638)

* Revert "fix(zsh): Set PROMPT just once (#2428)"

This reverts commit 6fd7d7b501.

* Reintroduce fixes around START_TIME

* Bring back disabling virtualenv

* Expand the jobstates before passing the number to starship

Credit goes to @vladimyr
This commit is contained in:
Felipe Seré 2021-04-29 15:16:25 +01:00 committed by GitHub
parent 00e64ecb74
commit 0e23526f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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")'