Commit f12f0bad authored by Dustin L. Howett's avatar Dustin L. Howett

prompt: rework process timing to use Get-History vs manual tracking

parent 67d605df
......@@ -59,32 +59,31 @@ Function pe_Sigil {
}
Function pe_LastCommandRunTime {
If ($global:_LastCommandTimeSpan -And ($global:_LastCommandTimeSpan.TotalSeconds) -Ge 10) {
# Format buffer: Total Minutes, Seconds, Milliseconds
# We could use total seconds in the second position, but it's only ever used as a primary
# unit if it numbers less than 60.
$fmtBuff = ([int]$global:_LastCommandTimeSpan.TotalMinutes, [int]$global:_LastCommandTimeSpan.Seconds, [int]$global:_LastCommandTimeSpan.Milliseconds)
$fmt = "{1}.{2:D3}s"
If (($global:_LastCommandTimeSpan.TotalSeconds) -Ge 60) {
$fmt = "{0}m{1}s"
}
Write-Host "[" -NoNewLine -ForegroundColor (Get-PromptColor CommandTimeBrackets)
Write-Host ($fmt -f $fmtBuff) -NoNewLine -ForegroundColor (Get-PromptColor CommandTime)
Write-Host "] " -NoNewLine -ForegroundColor (Get-PromptColor CommandTimeBrackets)
}
}
Add-PromptTask CalculateCommandLength {
If ($global:_LastCommandLaunchDate) {
$global:_LastCommandTimeSpan = (Get-Date).Subtract($global:_LastCommandLaunchDate)
$global:_LastCommandLaunchDate = $null
Set-PromptColor CommandTimeBrackets DarkYellow
Set-PromptColor CommandTime Yellow
If (($global:_LastCommandTimeSpan.TotalSeconds) -Ge 30) {
Set-PromptColor CommandTimeBrackets DarkRed
Set-PromptColor CommandTime Red
$lastCommand = Get-History -Count 1
If ($global:_LastHistoryId -Ne $lastCommand.Id) {
$duration = $lastCommand.EndExecutionTime.Subtract($lastCommand.StartExecutionTime)
If ($duration.TotalSeconds -Ge 10) {
# Format buffer: Total Minutes, Seconds, Milliseconds
# We could use total seconds in the second position, but it's only ever used as a primary
# unit if it numbers less than 60.
$fmtBuff = ([int]$duration.TotalMinutes, [int]$duration.Seconds, [int]$duration.Milliseconds)
$fmt = "{1}.{2:D3}s"
If (($duration.TotalSeconds) -Ge 60) {
$fmt = "{0}m{1}s"
}
$bracketColor = Get-PromptColor CommandDurationBracketsMedium
$timeColor = Get-PromptColor CommandDurationMedium
If (($duration.TotalSeconds) -Ge 30) {
$bracketColor = Get-PromptColor CommandDurationBracketsHigh
$timeColor = Get-PromptColor CommandDurationHigh
}
Write-Host "[" -NoNewLine -ForegroundColor $bracketColor
Write-Host ($fmt -f $fmtBuff) -NoNewLine -ForegroundColor $timeColor
Write-Host "] " -NoNewLine -ForegroundColor $bracketColor
}
$global:_LastHistoryId = $lastCommand.Id
}
}
......@@ -107,18 +106,13 @@ Set-PromptColor Sigil Green
Set-PromptColor Hostname White
Set-PromptColor DevEnv Green
Set-PromptColor CommandTime Black
Set-PromptColor CommandTimeBrackets Black
Set-PromptColor CommandDurationMedium Yellow
Set-PromptColor CommandDurationBracketsMedium DarkYellow
Set-PromptColor CommandDurationHigh Red
Set-PromptColor CommandDurationBracketsHigh DarkRed
# These are already defined by PromptEd
Set-PromptColor Path Magenta
Set-PromptColor Brackets Blue
Set-Prompt DHowettPrompt
If ($null -ne (Get-Module PSReadline)) {
Set-PSReadlineKeyHandler "Enter" -ScriptBlock {
$global:_LastCommandLaunchDate = Get-Date
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment