Skip to content

Commit 96db0b3

Browse files
JaykulmeganroggeTyriar
authored
Fix the PowerShell integration script microsoft#165022 (microsoft#165023)
* Don't set LastExitCode That's a magic variable in PowerShell * Force $? before running original prompt * Fix indentation Co-authored-by: Megan Rogge <[email protected]> Co-authored-by: Daniel Imms <[email protected]>
1 parent bf1697d commit 96db0b3

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,10 @@ $Global:__VSCodeOriginalPrompt = $function:Prompt
1717

1818
$Global:__LastHistoryId = -1
1919

20-
function Global:__VSCode-Get-LastExitCode {
21-
if ($? -eq $True) {
22-
return 0
23-
}
24-
# TODO: Should we just return a string instead?
25-
return -1
26-
}
2720

2821
function Global:Prompt() {
29-
$LastExitCode = $(__VSCode-Get-LastExitCode);
30-
$LastHistoryEntry = $(Get-History -Count 1)
22+
$FakeCode = [int]!$global:?
23+
$LastHistoryEntry = Get-History -Count 1
3124
# Skip finishing the command if the first command has not yet started
3225
if ($Global:__LastHistoryId -ne -1) {
3326
if ($LastHistoryEntry.Id -eq $Global:__LastHistoryId) {
@@ -50,7 +43,7 @@ function Global:Prompt() {
5043
$Result += "`a"
5144
# Command finished exit code
5245
# OSC 633 ; D [; <ExitCode>] ST
53-
$Result += "`e]633;D;$LastExitCode`a"
46+
$Result += "`e]633;D;$FakeCode`a"
5447
}
5548
}
5649
# Prompt started
@@ -59,7 +52,9 @@ function Global:Prompt() {
5952
# Current working directory
6053
# OSC 633 ; <Property>=<Value> ST
6154
$Result += if($pwd.Provider.Name -eq 'FileSystem'){"`e]633;P;Cwd=$($pwd.ProviderPath)`a"}
62-
# Write original prompt
55+
# Before running the original prompt, put $? back to what it was:
56+
if ($FakeCode -ne 0) { Write-Error "failure" -ea ignore }
57+
# Run the original prompt
6358
$Result += $Global:__VSCodeOriginalPrompt.Invoke()
6459
# Write command started
6560
$Result += "`e]633;B`a"

0 commit comments

Comments
 (0)