From b21904c9d3ac8ab8504badc5de5e1bf32484cbef Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Mon, 13 Dec 2021 10:15:02 +0100 Subject: [PATCH] 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 --- src/init/starship.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/init/starship.ps1 b/src/init/starship.ps1 index bd688bad..2fc6b046 100644 --- a/src/init/starship.ps1 +++ b/src/init/starship.ps1 @@ -63,6 +63,9 @@ function global:prompt { $process.StandardOutput.ReadToEnd(); } + $origDollarQuestion = $global:? + $origLastExitCode = $global:LASTEXITCODE + # Invoke precmd, if specified try { if (Test-Path function:Invoke-Starship-PreCommand) { @@ -70,9 +73,6 @@ function global:prompt { } } catch {} - $origDollarQuestion = $global:? - $origLastExitCode = $global:LASTEXITCODE - # @ makes sure the result is an array even if single or no values are returned $jobs = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count