mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-31 13:57:26 -08:00
parent
db8eac7c5d
commit
4e992d48d1
|
@ -286,27 +286,34 @@ Example:
|
||||||
}
|
}
|
||||||
|
|
||||||
function Update-PoshErrorCode {
|
function Update-PoshErrorCode {
|
||||||
$script:ExecutionTime = -1
|
|
||||||
$lastHistory = Get-History -ErrorAction Ignore -Count 1
|
$lastHistory = Get-History -ErrorAction Ignore -Count 1
|
||||||
|
|
||||||
|
# default values
|
||||||
|
$script:ErrorCode = 0
|
||||||
|
$script:ExecutionTime = -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)) {
|
||||||
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 ($script:OriginalLastExecutionStatus) {
|
if ($script:OriginalLastExecutionStatus) {
|
||||||
$script:ErrorCode = 0
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
$invocationInfo = try {
|
$invocationInfo = try {
|
||||||
# retrieve info of the most recent error
|
# retrieve info of the most recent error
|
||||||
$global:Error[0] | Where-Object { $_ -ne $null } | Select-Object -ExpandProperty InvocationInfo
|
$global:Error[0] | Where-Object { $_ -ne $null } | Select-Object -ExpandProperty InvocationInfo
|
||||||
} catch { $null }
|
} catch { $null }
|
||||||
|
|
||||||
# check if the last command caused the last error
|
# check if the last command caused the last error
|
||||||
if ($null -ne $invocationInfo -and $lastHistory.CommandLine -eq $invocationInfo.Line) {
|
if ($null -ne $invocationInfo -and $lastHistory.CommandLine -eq $invocationInfo.Line) {
|
||||||
$script:ErrorCode = 1
|
$script:ErrorCode = 1
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($script:OriginalLastExitCode -is [int] -and $script:OriginalLastExitCode -ne 0) {
|
if ($script:OriginalLastExitCode -is [int] -and $script:OriginalLastExitCode -ne 0) {
|
||||||
# native app exit code
|
# native app exit code
|
||||||
$script:ErrorCode = $script:OriginalLastExitCode
|
$script:ErrorCode = $script:OriginalLastExitCode
|
||||||
|
|
Loading…
Reference in a new issue