Skip to content

Commit f52f2ed

Browse files
committed
Use preexec $1 not history and send command
Fixes microsoft#143766
1 parent 30c8810 commit f52f2ed

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,7 @@ __vsc_update_cwd() {
6565

6666
__vsc_command_output_start() {
6767
builtin printf "\033]633;C\007"
68-
if [[ ! "$BASH_COMMAND" =~ ^__vsc_prompt* ]]; then
69-
__vsc_current_command=$BASH_COMMAND
70-
builtin printf "\033]633;E;$BASH_COMMAND\007"
71-
else
72-
__vsc_current_command=""
73-
builtin printf "\033]633;E\007"
74-
fi
68+
builtin printf "\033]633;E;$__vsc_current_command\007"
7569
}
7670

7771
__vsc_continuation_start() {
@@ -111,13 +105,19 @@ __vsc_update_prompt() {
111105

112106
__vsc_precmd() {
113107
__vsc_command_complete "$__vsc_status"
108+
__vsc_current_command=""
114109
__vsc_update_prompt
115110
}
116111

117112
__vsc_preexec() {
118113
if [ "$__vsc_in_command_execution" = "0" ]; then
119114
__vsc_initialized=1
120115
__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
121121
__vsc_command_output_start
122122
fi
123123
}

src/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then
3333
builtin return
3434
fi
3535

36-
__vsc_initialized="0"
3736
__vsc_in_command_execution="1"
38-
__vsc_last_history_id=0
37+
__vsc_current_command=""
3938

4039
__vsc_prompt_start() {
4140
builtin printf "\033]633;A\007"
@@ -51,6 +50,7 @@ __vsc_update_cwd() {
5150

5251
__vsc_command_output_start() {
5352
builtin printf "\033]633;C\007"
53+
builtin printf "\033]633;E;$__vsc_current_command\007"
5454
}
5555

5656
__vsc_continuation_start() {
@@ -70,17 +70,10 @@ __vsc_right_prompt_end() {
7070
}
7171

7272
__vsc_command_complete() {
73-
builtin local __vsc_history_id=$(builtin history | tail -n1 | awk '{print $1;}')
74-
# Don't write the command complete sequence for the first prompt without an associated command
75-
if [[ "$__vsc_initialized" == "1" ]]; then
76-
if [[ "$__vsc_history_id" == "$__vsc_last_history_id" ]]; then
77-
builtin printf "\033]633;D\007"
78-
else
79-
builtin printf "\033]633;D;%s\007" "$__vsc_status"
80-
__vsc_last_history_id=$__vsc_history_id
81-
fi
82-
else
73+
if [[ "$__vsc_current_command" == "" ]]; then
8374
builtin printf "\033]633;D\007"
75+
else
76+
builtin printf "\033]633;D;%s\007" "$__vsc_status"
8477
fi
8578
__vsc_update_cwd
8679
}
@@ -112,6 +105,7 @@ __vsc_precmd() {
112105
fi
113106

114107
__vsc_command_complete "$__vsc_status"
108+
__vsc_current_command=""
115109

116110
# in command execution
117111
if [ -n "$__vsc_in_command_execution" ]; then
@@ -125,8 +119,8 @@ __vsc_preexec() {
125119
if [ -n "$RPROMPT" ]; then
126120
RPROMPT="$__vsc_prior_rprompt"
127121
fi
128-
__vsc_initialized="1"
129122
__vsc_in_command_execution="1"
123+
__vsc_current_command=$1
130124
__vsc_command_output_start
131125
}
132126
add-zsh-hook precmd __vsc_precmd

0 commit comments

Comments
 (0)