Change:
This is a follow up from which worked around the majority case of an issue. See the workaround: The proper fix will involve sending both the exit code and the history ID over to VS Code which will then do what's happening now but also have the correct exit code to set, instead of assuming it's the last command's exit code. We should write a little script as part of this that alternates exit codes by setting/unsetting an environment variable so it's easier to test and verify.
The issue being worked around is actually caused by or being included in .
Good test case from
To verify: some commands , they should all show up in current session ctrl+c in between some commands, including typing out a command and hitting ctrl+c to abandon it , the lines with ctrl+c shouldn't show up several times, failed and success should match whether the exception was thrown.

Discussion:
builtin return fi <del> # Disable shell integration if HISTCONTROL is set to erase duplicate entries as the exit code # reporting relies on the duplicates existing if [[ "$HISTCONTROL" =~ .*erasedups.* ]]; then builtin unset VSCODE_SHELL_INTEGRATION builtin return fi </del> if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then builtin return fi

__vsc_custom_PS1="" __vsc_custom_PS2="" __vsc_in_command_execution="1" <del> __vsc_last_history_id=$(history 1 | awk '{print $1;}') </del> <ins> __vsc_current_command="" </ins> __vsc_prompt_start() { builtin printf "033]633;A007"

} __vsc_command_complete() { <del> local __vsc_history_id=$(builtin history 1 | awk '{print $1;}') if [[ "$__vsc_history_id" == "$__vsc_last_history_id" ]]; then </del> <ins> if [ "$__vsc_current_command" = "" ]; then </ins> builtin printf "033]633;D007" else builtin printf "033]633;D;%s007" "$__vsc_status" <del> __vsc_last_history_id=$__vsc_history_id </del> fi __vsc_update_cwd }

__vsc_precmd() { __vsc_command_complete "$__vsc_status" <ins> __vsc_current_command="" </ins> __vsc_update_prompt }

if [ "$__vsc_in_command_execution" = "0" ]; then __vsc_initialized=1 __vsc_in_command_execution="1" <ins> if [[ ! "$BASH_COMMAND" =~ ^__vsc_prompt* ]]; then __vsc_current_command=$BASH_COMMAND else __vsc_current_command="" fi </ins> __vsc_command_output_start fi }

builtin return fi <del> __vsc_initialized="0" </del> __vsc_in_command_execution="1" <del> __vsc_last_history_id=0 </del> <ins> __vsc_current_command="" </ins> __vsc_prompt_start() { builtin printf "033]633;A007"

__vsc_command_output_start() { builtin printf "033]633;C007" <ins> builtin printf "033]633;E;$__vsc_current_command007" </ins> } __vsc_continuation_start() {

} __vsc_command_complete() { <del> builtin local __vsc_history_id=$(builtin history | tail -n1 | awk '{print $1;}') # Don't write the command complete sequence for the first prompt without an associated command if [[ "$__vsc_initialized" == "1" ]]; then if [[ "$__vsc_history_id" == "$__vsc_last_history_id" ]]; then builtin printf "033]633;D007" else builtin printf "033]633;D;%s007" "$__vsc_status" __vsc_last_history_id=$__vsc_history_id fi else </del> <ins> if [[ "$__vsc_current_command" == "" ]]; then </ins> builtin printf "033]633;D007" <ins> else builtin printf "033]633;D;%s007" "$__vsc_status" </ins> fi __vsc_update_cwd }

fi __vsc_command_complete "$__vsc_status" <ins> __vsc_current_command="" </ins> # in command execution if [ -n "$__vsc_in_command_execution" ]; then

if [ -n "$RPROMPT" ]; then RPROMPT="$__vsc_prior_rprompt" fi <del> __vsc_initialized="1" </del> __vsc_in_command_execution="1" <ins> __vsc_current_command=$1 </ins> __vsc_command_output_start } add-zsh-hook precmd __vsc_precmd