Skip to content

Commit dc67523

Browse files
committed
Support shell integration in Windows PowerShell
By replacing `e with $([char]0x1b), we allow shell integration to work with Windows PowerShell, as the only problem seemed to be use of `e, which was an escape character added only to PowerShell Core, but the `[char]` equivalent works fine.
1 parent 3df5eee commit dc67523

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/vs/platform/terminal/node/terminalEnvironment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export function getShellIntegrationInjection(
127127

128128
// Windows
129129
if (isWindows) {
130-
if (shell === 'pwsh.exe') {
130+
if (shell === 'pwsh.exe' || shell === 'powershell.exe') {
131131
if (!originalArgs || arePwshImpliedArgs(originalArgs)) {
132132
newArgs = shellIntegrationArgs.get(ShellIntegrationExecutable.WindowsPwsh);
133133
} else if (arePwshLoginArgs(originalArgs)) {

src/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ function Global:Prompt() {
2525
if ($Global:__LastHistoryId -ne -1) {
2626
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
2727
# Don't provide a command line or exit code if there was no history entry (eg. ctrl+c, enter on no command)
28-
$Result = "`e]633;E`a"
29-
$Result += "`e]633;D`a"
28+
$Result = "$([char]0x1b)]633;E`a"
29+
$Result += "$([char]0x1b)]633;D`a"
3030
} else {
3131
# Command finished command line
3232
# OSC 633 ; A ; <CommandLine?> ST
33-
$Result = "`e]633;E;"
33+
$Result = "$([char]0x1b)]633;E;"
3434
# Sanitize the command line to ensure it can get transferred to the terminal and can be parsed
3535
# correctly. This isn't entirely safe but good for most cases, it's important for the Pt parameter
3636
# to only be composed of _printable_ characters as per the spec.
@@ -43,21 +43,21 @@ function Global:Prompt() {
4343
$Result += "`a"
4444
# Command finished exit code
4545
# OSC 633 ; D [; <ExitCode>] ST
46-
$Result += "`e]633;D;$FakeCode`a"
46+
$Result += "$([char]0x1b)]633;D;$FakeCode`a"
4747
}
4848
}
4949
# Prompt started
5050
# OSC 633 ; A ST
51-
$Result += "`e]633;A`a"
51+
$Result += "$([char]0x1b)]633;A`a"
5252
# Current working directory
5353
# OSC 633 ; <Property>=<Value> ST
54-
$Result += if($pwd.Provider.Name -eq 'FileSystem'){"`e]633;P;Cwd=$($pwd.ProviderPath)`a"}
54+
$Result += if($pwd.Provider.Name -eq 'FileSystem'){"$([char]0x1b)]633;P;Cwd=$($pwd.ProviderPath)`a"}
5555
# Before running the original prompt, put $? back to what it was:
5656
if ($FakeCode -ne 0) { Write-Error "failure" -ea ignore }
5757
# Run the original prompt
5858
$Result += $Global:__VSCodeOriginalPrompt.Invoke()
5959
# Write command started
60-
$Result += "`e]633;B`a"
60+
$Result += "$([char]0x1b)]633;B`a"
6161
$Global:__LastHistoryId = $LastHistoryEntry.Id
6262
return $Result
6363
}
@@ -69,13 +69,13 @@ if (Get-Module -Name PSReadLine) {
6969
function Global:PSConsoleHostReadLine {
7070
$tmp = $__VSCodeOriginalPSConsoleHostReadLine.Invoke()
7171
# Write command executed sequence directly to Console to avoid the new line from Write-Host
72-
[Console]::Write("`e]633;C`a")
72+
[Console]::Write("$([char]0x1b)]633;C`a")
7373
$tmp
7474
}
7575
}
7676

7777
# Set IsWindows property
78-
[Console]::Write("`e]633;P;IsWindows=$($IsWindows)`a")
78+
[Console]::Write("$([char]0x1b)]633;P;IsWindows=$($IsWindows)`a")
7979

8080
# Set always on key handlers which map to default VS Code keybindings
8181
function Set-MappedKeyHandler {

0 commit comments

Comments
 (0)