fix(pwsh): set initial value for $script:ExecutionTime

This commit is contained in:
L. Yeung 2022-08-10 00:23:47 +08:00 committed by Jan De Dobbeleer
parent 43c13c1762
commit d5a8ec3285

View file

@ -15,6 +15,7 @@ function global:Get-PoshStackCount {
New-Module -Name "oh-my-posh-core" -ScriptBlock { New-Module -Name "oh-my-posh-core" -ScriptBlock {
$script:ErrorCode = 0 $script:ErrorCode = 0
$script:ExecutionTime = 0
$script:OMPExecutable = ::OMP:: $script:OMPExecutable = ::OMP::
$script:ShellName = "::SHELL::" $script:ShellName = "::SHELL::"
$script:PSVersion = $PSVersionTable.PSVersion.ToString() $script:PSVersion = $PSVersionTable.PSVersion.ToString()
@ -286,17 +287,14 @@ Example:
} }
function Update-PoshErrorCode { function Update-PoshErrorCode {
$script:ExecutionTime = -1
$lastHistory = Get-History -ErrorAction Ignore -Count 1 $lastHistory = Get-History -ErrorAction Ignore -Count 1
# error code should be updated only when a non-empty command is run # error code should be updated only when a non-empty command is run
if (($null -eq $lastHistory) -or ($script:LastHistoryId -eq $lastHistory.Id)) { if (($null -eq $lastHistory) -or ($script:LastHistoryId -eq $lastHistory.Id)) {
$script:ExecutionTime = 0
return return
} }
$script:LastHistoryId = $lastHistory.Id $script:LastHistoryId = $lastHistory.Id
$script:ExecutionTime = ($lastHistory.EndExecutionTime - $lastHistory.StartExecutionTime).TotalMilliseconds $script:ExecutionTime = ($lastHistory.EndExecutionTime - $lastHistory.StartExecutionTime).TotalMilliseconds
if (-not ($script:ExecutionTime -is [int])) {
$script:ExecutionTime = 0
}
if ($script:OriginalLastExecutionStatus) { if ($script:OriginalLastExecutionStatus) {
$script:ErrorCode = 0 $script:ErrorCode = 0
return return