fix: Store $? and $LASTEXITCODE first in PowerShell (#3316)

These need to be stored before calling any PowerShell function or executable.
Otherwise the values will be overwritten and cannot be properly restored
or passed to starship.

Fixes: #3315
This commit is contained in:
Mika Fischer 2021-12-13 10:15:02 +01:00 committed by GitHub
parent 3c379693e1
commit b21904c9d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -63,6 +63,9 @@ function global:prompt {
$process.StandardOutput.ReadToEnd(); $process.StandardOutput.ReadToEnd();
} }
$origDollarQuestion = $global:?
$origLastExitCode = $global:LASTEXITCODE
# Invoke precmd, if specified # Invoke precmd, if specified
try { try {
if (Test-Path function:Invoke-Starship-PreCommand) { if (Test-Path function:Invoke-Starship-PreCommand) {
@ -70,9 +73,6 @@ function global:prompt {
} }
} catch {} } catch {}
$origDollarQuestion = $global:?
$origLastExitCode = $global:LASTEXITCODE
# @ makes sure the result is an array even if single or no values are returned # @ makes sure the result is an array even if single or no values are returned
$jobs = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count $jobs = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count