Created
September 21, 2019 16:57
-
-
Save wcarroll/2dbeeabc39284e4c02c02179806ebffd to your computer and use it in GitHub Desktop.
My PowerShell Profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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