Skip to content

Commit a10f30d

Browse files
authored
Merge pull request #244243 from microsoft/tyriar/244169
Ensure pwsh SI only emits E, C, D when in execution
2 parents d089fb1 + 2d24dfa commit a10f30d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1

+6-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ if ($ExecutionContext.SessionState.LanguageMode -ne "FullLanguage") {
1616
$Global:__VSCodeOriginalPrompt = $function:Prompt
1717

1818
$Global:__LastHistoryId = -1
19+
$Global:__VSCodeIsInExecution = $false
1920

2021
# Store the nonce in script scope and unset the global
2122
$Nonce = $env:VSCODE_NONCE
@@ -73,8 +74,10 @@ function Global:Prompt() {
7374
Set-StrictMode -Off
7475
$LastHistoryEntry = Get-History -Count 1
7576
$Result = ""
76-
# Skip finishing the command if the first command has not yet started
77-
if ($Global:__LastHistoryId -ne -1) {
77+
# Skip finishing the command if the first command has not yet started or an execution has not
78+
# yet begun
79+
if ($Global:__LastHistoryId -ne -1 -and $Global:__VSCodeIsInExecution -eq $true) {
80+
$Global:__VSCodeIsInExecution = $false
7881
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
7982
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
8083
$Result += "$([char]0x1b)]633;D`a"
@@ -124,10 +127,10 @@ function Global:Prompt() {
124127
# Only send the command executed sequence when PSReadLine is loaded, if not shell integration should
125128
# still work thanks to the command line sequence
126129
if (Get-Module -Name PSReadLine) {
127-
[Console]::Write("$([char]0x1b)]633;P;HasRichCommandDetection=True`a")
128130
$__VSCodeOriginalPSConsoleHostReadLine = $function:PSConsoleHostReadLine
129131
function Global:PSConsoleHostReadLine {
130132
$CommandLine = $__VSCodeOriginalPSConsoleHostReadLine.Invoke()
133+
$Global:__VSCodeIsInExecution = $true
131134

132135
# Command line
133136
# OSC 633 ; E [; <CommandLine> [; <Nonce>]] ST

0 commit comments

Comments
 (0)