Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save falkheiland/d221d84a7b2a383854747c127a612a89 to your computer and use it in GitHub Desktop.
Save falkheiland/d221d84a7b2a383854747c127a612a89 to your computer and use it in GitHub Desktop.
WindowsPowerShell Microsoft.PowerShell_profile.ps1
Import-Module -Name posh-git
function Prompt
{
try
{
Write-Host '[' -NoNewline
Write-Host ([DateTime]::now.ToString('HH:mm:ss')) -NoNewline -ForegroundColor Yellow
Write-Host '] ' -NoNewline
$History = Get-History -ErrorAction Ignore -Count 1
if ($History)
{
Write-Host '[' -NoNewline
$TimeSpan = New-TimeSpan -Start $History.StartExecutionTime -End $History.EndExecutionTime
switch ($TimeSpan)
{
{ $_.TotalSeconds -lt 1 }
{
[int]$d = $_.TotalMilliseconds
'{0}ms' -f ($d) |
Write-Host -ForegroundColor Black -NoNewline -BackgroundColor DarkGreen
break
}
{ $_.totalminutes -lt 1 }
{
[int]$d = $_.TotalSeconds
'{0}s' -f ($d) |
Write-Host -ForegroundColor Black -NoNewline -BackgroundColor DarkYellow
break
}
{ $_.totalminutes -ge 1 }
{
"{0:HH:mm:ss}" -f ([datetime]$TimeSpan.Ticks) |
Write-Host -ForegroundColor Gray -NoNewline -BackgroundColor Red
break
}
}
Write-Host '] ' -NoNewline
}
if (Get-Module Posh-git)
{
Write-VcsStatus
Write-Host ' ' -NoNewline
}
}
catch
{
Write-Error $_.Exception.Message
}
Write-Host ''
if (($PWD.Path.Split('\').count -gt 3))
{
Write-Host "$($PWD.path.split('\')[0], '...', $PWD.path.split('\')[-2], $PWD.path.split('\')[-1] -join ('\'))" -NoNewline
Set-PSReadLineOption -BellStyle None
}
else
{
Write-Host "$($PWD.path)" -NoNewline
}
" # "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment