Skip to content

Instantly share code, notes, and snippets.

@wcarroll
Created September 21, 2019 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wcarroll/2dbeeabc39284e4c02c02179806ebffd to your computer and use it in GitHub Desktop.
Save wcarroll/2dbeeabc39284e4c02c02179806ebffd to your computer and use it in GitHub Desktop.
My PowerShell Profile
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 {
if ($(Get-History).Count -gt 0) {
$ts = (Get-History)[-1].EndExecutionTime - (Get-History)[-1].StartExecutionTime
if ($ts.days -gt 0) {
$rtrStr = "[{0}d]" -f [Math]::Round($ts.totalDays, 2)
} elseif ($ts.hours -gt 0) {
$rtrStr = "[{0}h]" -f [Math]::Round($ts.totalHours, 2)
} elseif ($ts.Minutes -gt 0) {
$rtrStr = "[{0}m]" -f [Math]::Round($ts.totalMinutes, 2)
} elseif ($ts.Seconds -gt 0) {
$rtrStr = "[{0}s]" -f [Math]::Round($ts.totalSeconds, 2)
} else {
$rtrStr = "[{0}ms]" -f [Math]::Round($ts.Milliseconds, 2)
}
} else {
$rtrStr = "[0ms]"
}
$rtrStr
}
}
Set-Alias -Name gt -Value Get-LastCommandExecutionTime
function prompt {
return "$(Get-LastCommandExecutionTime) $pwd>"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment