Skip to content

Commit 36bedff

Browse files
authored
Merge pull request microsoft#151232 from microsoft/tyriar/150478
Make sure PS1/2 aren't re-wrapped in bash shell integration
2 parents d99d645 + b8b2e9c commit 36bedff

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# ---------------------------------------------------------------------------------------------
55

66
VSCODE_SHELL_INTEGRATION=1
7-
__vsc_initialized=0
87

98
if [ -z "$VSCODE_SHELL_LOGIN" ]; then
109
. ~/.bashrc
@@ -34,6 +33,11 @@ if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then
3433
builtin return
3534
fi
3635

36+
__vsc_initialized=0
37+
__vsc_original_PS1="$PS1"
38+
__vsc_original_PS2="$PS2"
39+
__vsc_custom_PS1=""
40+
__vsc_custom_PS2=""
3741
__vsc_in_command_execution="1"
3842
__vsc_last_history_id=$(history 1 | awk '{print $1;}')
3943

@@ -73,28 +77,32 @@ __vsc_command_complete() {
7377
}
7478

7579
__vsc_update_prompt() {
76-
__vsc_initialized=1
77-
__vsc_prior_prompt="$PS1"
78-
__vsc_in_command_execution=""
79-
PS1="\[$(__vsc_prompt_start)\]$PREFIX$PS1\[$(__vsc_prompt_end)\]"
80-
PS2="\[$(__vsc_continuation_start)\]$PS2\[$(__vsc_continuation_end)\]"
80+
# in command execution
81+
if [ "$__vsc_in_command_execution" = "1" ]; then
82+
# Wrap the prompt if it is not yet wrapped, if the PS1 changed this this was last set it
83+
# means the user re-exported the PS1 so we should re-wrap it
84+
if [[ "$__vsc_custom_PS1" == "" || "$__vsc_custom_PS1" != "$PS1" ]]; then
85+
__vsc_original_PS1=$PS1
86+
__vsc_custom_PS1="\[$(__vsc_prompt_start)\]$PREFIX$__vsc_original_PS1\[$(__vsc_prompt_end)\]"
87+
PS1="$__vsc_custom_PS1"
88+
fi
89+
if [[ "$__vsc_custom_PS2" == "" || "$__vsc_custom_PS2" != "$PS2" ]]; then
90+
__vsc_original_PS2=$PS2
91+
__vsc_custom_PS2="\[$(__vsc_continuation_start)\]$__vsc_original_PS2\[$(__vsc_continuation_end)\]"
92+
PS2="$__vsc_custom_PS2"
93+
fi
94+
__vsc_in_command_execution="0"
95+
fi
8196
}
8297

8398
__vsc_precmd() {
8499
__vsc_command_complete "$__vsc_status"
85-
86-
# in command execution
87-
if [ -n "$__vsc_in_command_execution" ]; then
88-
# non null
89-
__vsc_update_prompt
90-
fi
100+
__vsc_update_prompt
91101
}
92102

93103
__vsc_preexec() {
94-
if [ -z "${__vsc_initialized-}" ]; then
95-
PS1="$__vsc_prior_prompt"
96-
fi
97-
if [ -z "${__vsc_in_command_execution-}" ]; then
104+
if [ "$__vsc_in_command_execution" = "0" ]; then
105+
__vsc_initialized=1
98106
__vsc_in_command_execution="1"
99107
__vsc_command_output_start
100108
fi

0 commit comments

Comments
 (0)