From d5a8ec3285af3719a05c06a9a1799a67bf1e2159 Mon Sep 17 00:00:00 2001 From: "L. Yeung" Date: Wed, 10 Aug 2022 00:23:47 +0800 Subject: [PATCH] fix(pwsh): set initial value for `$script:ExecutionTime` --- src/shell/scripts/omp.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shell/scripts/omp.ps1 b/src/shell/scripts/omp.ps1 index 8944ee86..b6b947bb 100644 --- a/src/shell/scripts/omp.ps1 +++ b/src/shell/scripts/omp.ps1 @@ -15,6 +15,7 @@ function global:Get-PoshStackCount { New-Module -Name "oh-my-posh-core" -ScriptBlock { $script:ErrorCode = 0 + $script:ExecutionTime = 0 $script:OMPExecutable = ::OMP:: $script:ShellName = "::SHELL::" $script:PSVersion = $PSVersionTable.PSVersion.ToString() @@ -286,17 +287,14 @@ Example: } function Update-PoshErrorCode { - $script:ExecutionTime = -1 $lastHistory = Get-History -ErrorAction Ignore -Count 1 # error code should be updated only when a non-empty command is run if (($null -eq $lastHistory) -or ($script:LastHistoryId -eq $lastHistory.Id)) { + $script:ExecutionTime = 0 return } $script:LastHistoryId = $lastHistory.Id $script:ExecutionTime = ($lastHistory.EndExecutionTime - $lastHistory.StartExecutionTime).TotalMilliseconds - if (-not ($script:ExecutionTime -is [int])) { - $script:ExecutionTime = 0 - } if ($script:OriginalLastExecutionStatus) { $script:ErrorCode = 0 return