diff --git a/src/init/omp.fish b/src/init/omp.fish index 5be423608379..e6c92b96ce04 100644 --- a/src/init/omp.fish +++ b/src/init/omp.fish @@ -1,4 +1,11 @@ function fish_prompt set -l omp_duration "$CMD_DURATION$cmd_duration" - ::OMP:: --config ::CONFIG:: --error $status --execution-time $omp_duration --shell fish + if test "$omp_lastcommand" = "" + set omp_duration 0 + end + ::OMP:: --config ::CONFIG:: --error $status --execution-time $omp_duration +end + +function postexec_omp --on-event fish_postexec + set -gx omp_lastcommand $argv end diff --git a/src/init/omp.ps1 b/src/init/omp.ps1 index 350415c9c53c..746d5e44465c 100644 --- a/src/init/omp.ps1 +++ b/src/init/omp.ps1 @@ -6,6 +6,9 @@ $global:PoshSettings = New-Object -TypeName PSObject -Property @{ Theme = ""; } +# used to detect empty hit +$global:omp_lastHistoryId = -1 + $config = "::CONFIG::" if (Test-Path $config) { $global:PoshSettings.Theme = (Resolve-Path -Path $config).Path @@ -15,7 +18,7 @@ function global:Set-PoshContext {} function global:Set-PoshGitStatus { if (Get-Module -Name "posh-git") { - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification='Variable used later(not in this scope)')] + [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification = 'Variable used later(not in this scope)')] $Global:GitStatus = Get-GitStatus } } @@ -39,8 +42,9 @@ function global:Set-PoshGitStatus { $executionTime = -1 $history = Get-History -ErrorAction Ignore -Count 1 - if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime) { - $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds + if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime -and $global:omp_lastHistoryId -ne $history.Id) { + $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds + $global:omp_lastHistoryId = $history.Id } $omp = "::OMP::" $config = $global:PoshSettings.Theme