Skip to content

Commit b0213f8

Browse files
authored
Merge pull request microsoft#154562 from microsoft/tyriar/150241_2
Set status once, prevent preexec recursing
2 parents d7f814a + 3879c72 commit b0213f8

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,39 +110,42 @@ __vsc_precmd() {
110110
}
111111

112112
__vsc_preexec() {
113-
if [ "$__vsc_in_command_execution" = "0" ]; then
114-
__vsc_initialized=1
115-
__vsc_in_command_execution="1"
116-
if [[ ! "$BASH_COMMAND" =~ ^__vsc_prompt* ]]; then
117-
__vsc_current_command=$BASH_COMMAND
118-
else
119-
__vsc_current_command=""
120-
fi
121-
__vsc_command_output_start
113+
__vsc_initialized=1
114+
if [[ ! "$BASH_COMMAND" =~ ^__vsc_prompt* ]]; then
115+
__vsc_current_command=$BASH_COMMAND
116+
else
117+
__vsc_current_command=""
122118
fi
119+
__vsc_command_output_start
123120
}
124121

125122
# Debug trapping/preexec inspired by starship (ISC)
126123
if [[ -n "${bash_preexec_imported:-}" ]]; then
127124
__vsc_preexec_only() {
128-
__vsc_status="$?"
129-
__vsc_preexec
125+
if [ "$__vsc_in_command_execution" = "0" ]; then
126+
__vsc_in_command_execution="1"
127+
__vsc_preexec
128+
fi
130129
}
131130
precmd_functions+=(__vsc_prompt_cmd)
132131
preexec_functions+=(__vsc_preexec_only)
133132
else
134133
__vsc_dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
135134
if [[ -z "$__vsc_dbg_trap" ]]; then
136135
__vsc_preexec_only() {
137-
__vsc_status="$?"
138-
__vsc_preexec
136+
if [ "$__vsc_in_command_execution" = "0" ]; then
137+
__vsc_in_command_execution="1"
138+
__vsc_preexec
139+
fi
139140
}
140141
trap '__vsc_preexec_only "$_"' DEBUG
141142
elif [[ "$__vsc_dbg_trap" != '__vsc_preexec "$_"' && "$__vsc_dbg_trap" != '__vsc_preexec_all "$_"' ]]; then
142143
__vsc_preexec_all() {
143-
__vsc_status="$?"
144-
builtin eval ${__vsc_dbg_trap}
145-
__vsc_preexec
144+
if [ "$__vsc_in_command_execution" = "0" ]; then
145+
__vsc_in_command_execution="1"
146+
builtin eval ${__vsc_dbg_trap}
147+
__vsc_preexec
148+
fi
146149
}
147150
trap '__vsc_preexec_all "$_"' DEBUG
148151
fi
@@ -151,6 +154,7 @@ fi
151154
__vsc_update_prompt
152155

153156
__vsc_prompt_cmd_original() {
157+
__vsc_status="$?"
154158
if [[ ${IFS+set} ]]; then
155159
__vsc_original_ifs="$IFS"
156160
fi

0 commit comments

Comments
 (0)