Fix Bash integration clobbering $?
for PROMPT_COMMAND
#226929
Merged
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #221393, ohmybash/oh-my-bash#595
Problem
The exit status
$?
that the first command ofPROMPT_COMMAND
sees is broken by VSCode's Bash integration. It becomes always 0 (success) even when the previous command fails. This becomes a problem for a hook inPROMPT_COMMAND
that updates the prompt contentPS1
based on the previous exit status. For example, this affects hooks that make the prompt green/red when the previous command succeeds/fails.Cause
This problem was introduced by PR #208364. The exit status is supposed to be restored by the line
__vsc_restore_exit_code "${__vsc_status}"
, but the culprit PR insertedlocal cmd
after restoring the exit code. Then,local cmd
again overwrites the exit status to 0, whichPROMPT_COMMAND
sees.Solution
The line
local cmd
should be performed before restoring the exit status.