From 6e24358052eea9267138225c81ff6f4986dcaadf Mon Sep 17 00:00:00 2001 From: Kevin Song <4605384+chipbuster@users.noreply.github.com> Date: Sun, 30 Jan 2022 03:52:51 -0600 Subject: [PATCH] fix(bash): Restore previous exit status in bash init (#3521) * fix: Restore previous exit status in bash init * Do it correctly this time --- src/init/starship.bash | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/init/starship.bash b/src/init/starship.bash index 6d1d2ae31e50..790c2c1244fa 100644 --- a/src/init/starship.bash +++ b/src/init/starship.bash @@ -12,6 +12,9 @@ # drawn, and only start the timer if this flag is present. That way, timing is # for the entire command, and not just a portion of it. +# A way to set '$?', since bash does not allow assigning to '$?' directly +function _starship_set_return() { return "${1:-0}"; } + # Will be run before *every* command (even ones in pipes!) starship_preexec() { # Save previous command's last argument, otherwise it will be set to "starship_preexec" @@ -43,6 +46,10 @@ starship_precmd() { # Run the bash precmd function, if it's set. If not set, evaluates to no-op "${starship_precmd_user_func-:}" + # Set $? to the preserved value before running additional parts of the prompt + # command pipeline, which may rely on it. + _starship_set_return "$STARSHIP_CMD_STATUS" + eval "$_PRESERVED_PROMPT_COMMAND" # Prepare the timer data, if needed.