|
4 | 4 | # ---------------------------------------------------------------------------------------------
|
5 | 5 |
|
6 | 6 | VSCODE_SHELL_INTEGRATION=1
|
7 |
| -__vsc_initialized=0 |
8 | 7 |
|
9 | 8 | if [ -z "$VSCODE_SHELL_LOGIN" ]; then
|
10 | 9 | . ~/.bashrc
|
@@ -34,6 +33,11 @@ if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then
|
34 | 33 | builtin return
|
35 | 34 | fi
|
36 | 35 |
|
| 36 | +__vsc_initialized=0 |
| 37 | +__vsc_original_PS1="$PS1" |
| 38 | +__vsc_original_PS2="$PS2" |
| 39 | +__vsc_custom_PS1="" |
| 40 | +__vsc_custom_PS2="" |
37 | 41 | __vsc_in_command_execution="1"
|
38 | 42 | __vsc_last_history_id=$(history 1 | awk '{print $1;}')
|
39 | 43 |
|
@@ -73,28 +77,32 @@ __vsc_command_complete() {
|
73 | 77 | }
|
74 | 78 |
|
75 | 79 | __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 |
81 | 96 | }
|
82 | 97 |
|
83 | 98 | __vsc_precmd() {
|
84 | 99 | __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 |
91 | 101 | }
|
92 | 102 |
|
93 | 103 | __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 |
98 | 106 | __vsc_in_command_execution="1"
|
99 | 107 | __vsc_command_output_start
|
100 | 108 | fi
|
|
0 commit comments