Skip to content

Commit b90b9d1

Browse files
Tyriarmeganrogge
andcommitted
Fix PS1-based bash shell integration
Fixes microsoft#150877 Co-Authored-By: Megan Rogge <[email protected]>
1 parent 5665196 commit b90b9d1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
# Licensed under the MIT License. See License.txt in the project root for license information.
44
# ---------------------------------------------------------------------------------------------
55

6+
# set -x
7+
68
VSCODE_SHELL_INTEGRATION=1
9+
__vsc_initialized=0
710

811
if [ -z "$VSCODE_SHELL_LOGIN" ]; then
912
. ~/.bashrc
@@ -72,6 +75,7 @@ __vsc_command_complete() {
7275
}
7376

7477
__vsc_update_prompt() {
78+
__vsc_initialized=1
7579
__vsc_prior_prompt="$PS1"
7680
__vsc_in_command_execution=""
7781
PS1="\[$(__vsc_prompt_start)\]$PREFIX$PS1\[$(__vsc_prompt_end)\]"
@@ -89,25 +93,28 @@ __vsc_precmd() {
8993
}
9094

9195
__vsc_preexec() {
92-
PS1="$__vsc_prior_prompt"
96+
if [ -z "${__vsc_initialized-}" ]; then
97+
PS1="$__vsc_prior_prompt"
98+
fi
9399
if [ -z "${__vsc_in_command_execution-}" ]; then
94100
__vsc_in_command_execution="1"
95101
__vsc_command_output_start
96102
fi
97103
}
98104

99105
# Debug trapping/preexec inspired by starship (ISC)
100-
dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
101-
if [[ -z "$dbg_trap" ]]; then
106+
__vsc_dbg_trap="$(trap -p DEBUG | cut -d' ' -f3 | tr -d \')"
107+
if [[ -z "$__vsc_dbg_trap" ]]; then
102108
__vsc_preexec_only() {
103109
__vsc_status="$?"
104110
__vsc_preexec
105111
}
106112
trap '__vsc_preexec_only "$_"' DEBUG
107-
elif [[ "$dbg_trap" != '__vsc_preexec "$_"' && "$dbg_trap" != '__vsc_preexec_all "$_"' ]]; then
113+
elif [[ "$__vsc_dbg_trap" != '__vsc_preexec "$_"' && "$__vsc_dbg_trap" != '__vsc_preexec_all "$_"' ]]; then
108114
__vsc_preexec_all() {
109115
__vsc_status="$?"
110-
local PREV_LAST_ARG=$1 ; $dbg_trap; __vsc_preexec; : "$PREV_LAST_ARG";
116+
builtin eval ${__vsc_dbg_trap}
117+
__vsc_preexec
111118
}
112119
trap '__vsc_preexec_all "$_"' DEBUG
113120
fi

0 commit comments

Comments
 (0)