Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bash integration clobbering $? for PROMPT_COMMAND #226929

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

akinomyoga
Copy link
Contributor

Fixes #221393, ohmybash/oh-my-bash#595

Problem

The exit status $? that the first command of PROMPT_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 in PROMPT_COMMAND that updates the prompt content PS1 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 inserted local cmd after restoring the exit code. Then, local cmd again overwrites the exit status to 0, which PROMPT_COMMAND sees.

Solution

The line local cmd should be performed before restoring the exit status.

@Tyriar Tyriar added this to the August 2024 milestone Aug 29, 2024
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this, looks safe enough to merge for the upcoming release 👍

@Tyriar Tyriar merged commit 4711122 into microsoft:main Aug 29, 2024
6 checks passed
@akinomyoga akinomyoga deleted the patch-1 branch August 29, 2024 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants