@@ -75,7 +75,7 @@ starship_precmd() {
75
75
STARSHIP_END_TIME=$( ::STARSHIP:: time)
76
76
STARSHIP_DURATION=$(( STARSHIP_END_TIME - STARSHIP_START_TIME))
77
77
ARGS+=( --cmd-duration=" ${STARSHIP_DURATION} " )
78
- unset STARSHIP_START_TIME
78
+ STARSHIP_START_TIME= " "
79
79
fi
80
80
PS1=" $( ::STARSHIP:: prompt " ${ARGS[@]} " ) "
81
81
if [[ ${BLE_ATTACHED-} ]]; then
@@ -98,17 +98,27 @@ elif [[ -n "${bash_preexec_imported:-}" || -n "${__bp_imported:-}" || -n "${pree
98
98
preexec_functions+=(starship_preexec_all)
99
99
precmd_functions+=(starship_precmd)
100
100
else
101
- # We want to avoid destroying an existing DEBUG hook. If we detect one, create
102
- # a new function that runs both the existing function AND our function, then
103
- # re-trap DEBUG to use this new function. This prevents a trap clobber.
104
- dbg_trap=" $( trap -p DEBUG | cut -d' ' -f3 | tr -d \' ) "
105
- if [[ -z " $dbg_trap " ]]; then
106
- trap ' starship_preexec "$_"' DEBUG
107
- elif [[ " $dbg_trap " != ' starship_preexec "$_"' && " $dbg_trap " != ' starship_preexec_all "$_"' ]]; then
108
- starship_preexec_all () {
109
- local PREV_LAST_ARG=$1 ; $dbg_trap ; starship_preexec; : " $PREV_LAST_ARG " ;
101
+ if [[ -n " ${BASH_VERSION-} " ]] && [[ " ${BASH_VERSINFO[0]} " -gt 4 || ( " ${BASH_VERSINFO[0]} " -eq 4 && " ${BASH_VERSINFO[1]} " -ge 4 ) ]]; then
102
+ starship_preexec_ps0 () {
103
+ ::STARSHIP:: time
110
104
}
111
- trap ' starship_preexec_all "$_"' DEBUG
105
+ # In order to set STARSHIP_START_TIME use an arithmetic expansion that evaluates to 0
106
+ # To avoid printing anything, use the return value in an ${var:offset:length} substring expansion
107
+ # with offset and length evaluating to 0.
108
+ PS0=' ${STARSHIP_START_TIME:$((STARSHIP_START_TIME="$(starship_preexec_ps0)",STARSHIP_PREEXEC_READY=0,0)):0}' " ${PS0-} "
109
+ else
110
+ # We want to avoid destroying an existing DEBUG hook. If we detect one, create
111
+ # a new function that runs both the existing function AND our function, then
112
+ # re-trap DEBUG to use this new function. This prevents a trap clobber.
113
+ dbg_trap=" $( trap -p DEBUG | cut -d' ' -f3 | tr -d \' ) "
114
+ if [[ -z " $dbg_trap " ]]; then
115
+ trap ' starship_preexec "$_"' DEBUG
116
+ elif [[ " $dbg_trap " != ' starship_preexec "$_"' && " $dbg_trap " != ' starship_preexec_all "$_"' ]]; then
117
+ starship_preexec_all () {
118
+ local PREV_LAST_ARG=$1 ; $dbg_trap ; starship_preexec; : " $PREV_LAST_ARG " ;
119
+ }
120
+ trap ' starship_preexec_all "$_"' DEBUG
121
+ fi
112
122
fi
113
123
114
124
# Finally, prepare the precmd function and set up the start time. We will avoid to
0 commit comments