mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-10 23:30:57 +00:00
feat(bash): use PS0 for preexec hook (#5735)
This commit is contained in:
parent
7290c5e368
commit
ae711c0f33
@ -75,7 +75,7 @@ starship_precmd() {
|
|||||||
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))
|
||||||
ARGS+=( --cmd-duration="${STARSHIP_DURATION}")
|
ARGS+=( --cmd-duration="${STARSHIP_DURATION}")
|
||||||
unset STARSHIP_START_TIME
|
STARSHIP_START_TIME=""
|
||||||
fi
|
fi
|
||||||
PS1="$(::STARSHIP:: prompt "${ARGS[@]}")"
|
PS1="$(::STARSHIP:: prompt "${ARGS[@]}")"
|
||||||
if [[ ${BLE_ATTACHED-} ]]; then
|
if [[ ${BLE_ATTACHED-} ]]; then
|
||||||
@ -97,6 +97,15 @@ elif [[ -n "${bash_preexec_imported:-}" || -n "${__bp_imported:-}" || -n "${pree
|
|||||||
starship_preexec_all(){ starship_preexec "$_"; }
|
starship_preexec_all(){ starship_preexec "$_"; }
|
||||||
preexec_functions+=(starship_preexec_all)
|
preexec_functions+=(starship_preexec_all)
|
||||||
precmd_functions+=(starship_precmd)
|
precmd_functions+=(starship_precmd)
|
||||||
|
else
|
||||||
|
if [[ -n "${BASH_VERSION-}" ]] && [[ "${BASH_VERSINFO[0]}" -gt 4 || ( "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -ge 4 ) ]]; then
|
||||||
|
starship_preexec_ps0() {
|
||||||
|
::STARSHIP:: time
|
||||||
|
}
|
||||||
|
# In order to set STARSHIP_START_TIME use an arithmetic expansion that evaluates to 0
|
||||||
|
# To avoid printing anything, use the return value in an ${var:offset:length} substring expansion
|
||||||
|
# with offset and length evaluating to 0.
|
||||||
|
PS0='${STARSHIP_START_TIME:$((STARSHIP_START_TIME="$(starship_preexec_ps0)",STARSHIP_PREEXEC_READY=0,0)):0}'"${PS0-}"
|
||||||
else
|
else
|
||||||
# We want to avoid destroying an existing DEBUG hook. If we detect one, create
|
# We want to avoid destroying an existing DEBUG hook. If we detect one, create
|
||||||
# a new function that runs both the existing function AND our function, then
|
# a new function that runs both the existing function AND our function, then
|
||||||
@ -110,6 +119,7 @@ else
|
|||||||
}
|
}
|
||||||
trap 'starship_preexec_all "$_"' DEBUG
|
trap 'starship_preexec_all "$_"' DEBUG
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Finally, prepare the precmd function and set up the start time. We will avoid to
|
# Finally, prepare the precmd function and set up the start time. We will avoid to
|
||||||
# add multiple instances of the starship function and keep other user functions if any.
|
# add multiple instances of the starship function and keep other user functions if any.
|
||||||
|
Loading…
Reference in New Issue
Block a user