Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Two-line prompt with last command execution time and tail of present working directory - modification of FatherJack's prompt, which was inspired by FriedrichWeinmann
function Prompt {
try {
$history = Get-History -ErrorAction Ignore -Count 1
if ($history) {
$ts = New-TimeSpan $history.StartExecutionTime $history.EndExecutionTime
Write-Host "[" -NoNewline
switch ($ts) {
{$_.TotalSeconds -lt 1} {
[decimal]$d = $_.TotalMilliseconds
'{0:f3}ms' -f ($d) | Write-Host -ForegroundColor Black -NoNewline -BackgroundColor DarkGreen
break
}
{$_.totalminutes -lt 1} {
[decimal]$d = $_.TotalSeconds
'{0:f3}s' -f ($d) | Write-Host -ForegroundColor Black -NoNewline -BackgroundColor DarkYellow
break
}
{$_.totalminutes -lt 30} {
[decimal]$d = $ts.TotalMinutes
'{0:f3}m' -f ($d) | Write-Host -ForegroundColor Gray -NoNewline -BackgroundColor Red
break
}
Default {
$_.Milliseconds | Write-Host -ForegroundColor Gray -NoNewline
}
}
}
}
catch { }
# show the drive and then last 2 directories of current path
if (($pwd.Path.Split('\').count -gt 2)){
write-host "] $($pwd.path.split('\')[0], '...', $pwd.path.split('\')[-2], $pwd.path.split('\')[-1] -join ('\'))" -NoNewline
}
else{
Write-Host "] $($pwd.path)" -NoNewline
}
"> "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.