mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-10 15:20:55 +00:00
fix(bash): Handle Unbound Variables Errors in Bash (#4972)
* fix: unbound bp pipestatus variable * fix: unbound preserved prompt command variable * fix: unbound starship start time variable * fix: unbound preexec_functions, precmd_functions and PROMPT_COMMAND variables.
This commit is contained in:
parent
da4af64dc5
commit
7093d5cd84
@ -36,7 +36,7 @@ starship_precmd() {
|
||||
if [[ ${BLE_ATTACHED-} && ${#BLE_PIPESTATUS[@]} -gt 0 ]]; then
|
||||
STARSHIP_PIPE_STATUS=("${BLE_PIPESTATUS[@]}")
|
||||
fi
|
||||
if [[ "${#BP_PIPESTATUS[@]}" -gt "${#STARSHIP_PIPE_STATUS[@]}" ]]; then
|
||||
if [[ -n "${BP_PIPESTATUS-}" ]] && [[ "${#BP_PIPESTATUS[@]}" -gt "${#STARSHIP_PIPE_STATUS[@]}" ]]; then
|
||||
STARSHIP_PIPE_STATUS=(${BP_PIPESTATUS[@]})
|
||||
fi
|
||||
|
||||
@ -65,11 +65,13 @@ starship_precmd() {
|
||||
# command pipeline, which may rely on it.
|
||||
_starship_set_return "$STARSHIP_CMD_STATUS"
|
||||
|
||||
eval "$_PRESERVED_PROMPT_COMMAND"
|
||||
if [[ -n "${_PRESERVED_PROMPT_COMMAND-}" ]]; then
|
||||
eval "$_PRESERVED_PROMPT_COMMAND"
|
||||
fi
|
||||
|
||||
local -a ARGS=(--terminal-width="${COLUMNS}" --status="${STARSHIP_CMD_STATUS}" --pipestatus="${STARSHIP_PIPE_STATUS[*]}" --jobs="${NUM_JOBS}")
|
||||
# Prepare the timer data, if needed.
|
||||
if [[ $STARSHIP_START_TIME ]]; then
|
||||
if [[ -n "${STARSHIP_START_TIME-}" ]]; then
|
||||
STARSHIP_END_TIME=$(::STARSHIP:: time)
|
||||
STARSHIP_DURATION=$((STARSHIP_END_TIME - STARSHIP_START_TIME))
|
||||
ARGS+=( --cmd-duration="${STARSHIP_DURATION}")
|
||||
@ -90,7 +92,7 @@ if [[ ${BLE_VERSION-} && _ble_version -ge 400 ]]; then
|
||||
blehook PRECMD!='starship_precmd'
|
||||
# If the user appears to be using https://github.com/rcaloras/bash-preexec,
|
||||
# then hook our functions into their framework.
|
||||
elif [[ "${__bp_imported:-}" == "defined" || $preexec_functions || $precmd_functions ]]; then
|
||||
elif [[ "${__bp_imported:-}" == "defined" || -n "${preexec_functions-}" || -n "${precmd_functions-}" ]]; then
|
||||
# bash-preexec needs a single function--wrap the args into a closure and pass
|
||||
starship_preexec_all(){ starship_preexec "$_"; }
|
||||
preexec_functions+=(starship_preexec_all)
|
||||
@ -111,7 +113,7 @@ else
|
||||
|
||||
# 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.
|
||||
if [[ -z "$PROMPT_COMMAND" ]]; then
|
||||
if [[ -z "${PROMPT_COMMAND-}" ]]; then
|
||||
PROMPT_COMMAND="starship_precmd"
|
||||
elif [[ "$PROMPT_COMMAND" != *"starship_precmd"* ]]; then
|
||||
# Appending to PROMPT_COMMAND breaks exit status ($?) checking.
|
||||
|
Loading…
Reference in New Issue
Block a user