Skip to content

Commit

Permalink
feat: don't keep duration when no command is entered
Browse files Browse the repository at this point in the history
pwsh and fish alignement
  • Loading branch information
lnu authored and JanDeDobbeleer committed Mar 19, 2021
1 parent 875214b commit 838567c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 8 additions & 1 deletion 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
10 changes: 7 additions & 3 deletions src/init/omp.ps1
Expand Up @@ -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
Expand All @@ -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
}
}
Expand All @@ -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
Expand Down

0 comments on commit 838567c

Please sign in to comment.