fix(bash): Restore previous exit status in bash init (#3521)

* fix: Restore previous exit status in bash init

* Do it correctly this time
This commit is contained in:
Kevin Song 2022-01-30 03:52:51 -06:00 committed by GitHub
parent 65f29754d3
commit 6e24358052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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.