Skip to content

Commit

Permalink
fix(bash): Restore previous exit status in bash init (#3521)
Browse files Browse the repository at this point in the history
* fix: Restore previous exit status in bash init

* Do it correctly this time
  • Loading branch information
chipbuster committed Jan 30, 2022
1 parent 65f2975 commit 6e24358
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/init/starship.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 6e24358

Please sign in to comment.