Skip to content

Instantly share code, notes, and snippets.

@henriksen
Last active June 17, 2018 12:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriksen/b65ba022050ffc0ff31d7e668570279b to your computer and use it in GitHub Desktop.
Save henriksen/b65ba022050ffc0ff31d7e668570279b to your computer and use it in GitHub Desktop.
[...]
Function Get-LastCommandExecutionTime {
<#
.SYNOPSIS
Gets the execution time of the last command used.
.EXAMPLE
Get-LastCommandExecutionTime
Description
-----------
Gets the last execution time of the last command run.
#>
Process {
Try {
(Get-History)[-1].EndExecutionTime - (Get-History)[-1].StartExecutionTime
}
Catch {
[timespan]::fromseconds(0);
}
}
}
[...]
function prompt {
$lastExecutionTimeSpan = Get-LastCommandExecutionTime
$lastExecutionTime = "{0}{1}{2:00}s" -f $(if ($lastExecutionTimeSpan.TotalMinutes -ge 1.0d)
{"$([Math]::Floor($lastExecutionTimeSpan.TotalMinutes))m "} else {""}),
$(if ($lastExecutionTimeSpan.TotalMilliseconds -lt 1000) { ">"} else {""}),
$(if ($lastExecutionTimeSpan.TotalMilliseconds -lt 1000) { "1"} else {[int]($lastExecutionTimeSpan.Seconds + ($lastExecutionTimeSpan.Milliseconds / 1000))})
[...]
Write-Host $curPath -ForegroundColor Green -NoNewline
Write-Host " • took " -ForegroundColor White -NoNewline
Write-Host "$lastExecutionTime" -ForegroundColor Yellow
[...]
"$('>' * ($nestedPromptLevel + 1)) "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment