Skip to content

Instantly share code, notes, and snippets.

@SQLDBAWithABeard
Last active November 30, 2020 18:32
Show Gist options
  • Save SQLDBAWithABeard/c9c8ae78449ef9cbd601144c538583e8 to your computer and use it in GitHub Desktop.
Save SQLDBAWithABeard/c9c8ae78449ef9cbd601144c538583e8 to your computer and use it in GitHub Desktop.
Prompt
[System.Console]::OutputEncoding = [System.Text.Encoding]::ASCII
# borrowing heavily from https://dbatools.io/prompt but formatting the execution time without using the DbaTimeSpanPretty C# type
function Prompt {
if($PSVersionTable.PSVersion.Major -eq 6){
Write-Host (Get-Date -Format "PS 6 ") -ForegroundColor Yellow -NoNewline
}
elseif($PSVersionTable.PSVersion.Major -eq 5){
Write-Host (Get-Date -Format "PS 5 ") -ForegroundColor Yellow -NoNewline
}
elseif($PSVersionTable.PSVersion.Major -eq 7){
Write-Host (Get-Date -Format "PS 7 ") -ForegroundColor Yellow -NoNewline
}
Write-Host (Get-Date -Format "ddd HH:mm") -ForegroundColor Gray -NoNewline
try {
$history = Get-History -ErrorAction Ignore -Count 1
if ($history) {
$ts = New-TimeSpan $history.StartExecutionTime $history.EndExecutionTime
switch ($ts) {
{$_.totalminutes -gt 1 -and $_.totalminutes -lt 30 } {
Write-Host "[" -ForegroundColor Red -NoNewline
[decimal]$d = $_.TotalMinutes
"{0:f3}m" -f ($d) | Write-Host -ForegroundColor Red -NoNewline
Write-Host "]" -ForegroundColor Red -NoNewline
}
{$_.totalminutes -le 1 -and $_.TotalSeconds -gt 1} {
Write-Host "[" -ForegroundColor Yellow -NoNewline
[decimal]$d = $_.TotalSeconds
"{0:f3}s" -f ($d) | Write-Host -ForegroundColor Yellow -NoNewline
Write-Host "]" -ForegroundColor Yellow -NoNewline
}
{$_.TotalSeconds -le 1} {
[decimal]$d = $_.TotalMilliseconds
Write-Host " [" -ForegroundColor Green -NoNewline
"{0:f3}ms" -f ($d) | Write-Host -ForegroundColor Green -NoNewline
Write-Host "]" -ForegroundColor Green -NoNewline
}
Default {
$_.Milliseconds | Write-Host -ForegroundColor Gray -NoNewline
}
}
}
}
catch { }
$status = Get-GitStatus -Force
$behind = $($status.BehindBy)
$Infront = $($status.AheadBy)
Write-Host " $($pwd.path.Split('\')[-2..-1] -join '\')" -NoNewline
Write-Host " [$($status.Branch)]" -ForegroundColor DarkMagenta -NoNewline
Write-Host " $([char]8595) $behind $([char]8593) $Infront > " -ForegroundColor Green
"> "
}
@Cirzen
Copy link

Cirzen commented Apr 4, 2019

Line 19 has the square bracket the wrong way round.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment