Skip to content

Commit eab7ba2

Browse files
authored
Merge pull request microsoft#154363 from microsoft/tyriar/143766
Remove reliance on history and always send command line
2 parents db734e8 + f52f2ed commit eab7ba2

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ if [[ "$PROMPT_COMMAND" =~ .*(' '.*\;)|(\;.*' ').* ]]; then
3939
builtin return
4040
fi
4141

42-
# Disable shell integration if HISTCONTROL is set to erase duplicate entries as the exit code
43-
# reporting relies on the duplicates existing
44-
if [[ "$HISTCONTROL" =~ .*erasedups.* ]]; then
45-
builtin unset VSCODE_SHELL_INTEGRATION
46-
builtin return
47-
fi
48-
4942
if [ -z "$VSCODE_SHELL_INTEGRATION" ]; then
5043
builtin return
5144
fi
@@ -56,7 +49,7 @@ __vsc_original_PS2="$PS2"
5649
__vsc_custom_PS1=""
5750
__vsc_custom_PS2=""
5851
__vsc_in_command_execution="1"
59-
__vsc_last_history_id=$(history 1 | awk '{print $1;}')
52+
__vsc_current_command=""
6053

6154
__vsc_prompt_start() {
6255
builtin printf "\033]633;A\007"
@@ -72,6 +65,7 @@ __vsc_update_cwd() {
7265

7366
__vsc_command_output_start() {
7467
builtin printf "\033]633;C\007"
68+
builtin printf "\033]633;E;$__vsc_current_command\007"
7569
}
7670

7771
__vsc_continuation_start() {
@@ -83,12 +77,10 @@ __vsc_continuation_end() {
8377
}
8478

8579
__vsc_command_complete() {
86-
local __vsc_history_id=$(builtin history 1 | awk '{print $1;}')
87-
if [[ "$__vsc_history_id" == "$__vsc_last_history_id" ]]; then
80+
if [ "$__vsc_current_command" = "" ]; then
8881
builtin printf "\033]633;D\007"
8982
else
9083
builtin printf "\033]633;D;%s\007" "$__vsc_status"
91-
__vsc_last_history_id=$__vsc_history_id
9284
fi
9385
__vsc_update_cwd
9486
}
@@ -113,13 +105,19 @@ __vsc_update_prompt() {
113105

114106
__vsc_precmd() {
115107
__vsc_command_complete "$__vsc_status"
108+
__vsc_current_command=""
116109
__vsc_update_prompt
117110
}
118111

119112
__vsc_preexec() {
120113
if [ "$__vsc_in_command_execution" = "0" ]; then
121114
__vsc_initialized=1
122115
__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
123121
__vsc_command_output_start
124122
fi
125123
}

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)