Skip to content

Instantly share code, notes, and snippets.

@bjorkstromm
Last active September 11, 2024 12:10
Show Gist options
  • Save bjorkstromm/e9ac27a0b741a2bd8bbb2c93a282ad24 to your computer and use it in GitHub Desktop.
Save bjorkstromm/e9ac27a0b741a2bd8bbb2c93a282ad24 to your computer and use it in GitHub Desktop.
pwsh prompt
function prompt {
$ESC = [char]27
$time = "$ESC[93m$([System.DateTime]::Now.ToString("HH:mm:ss"))$ESC[0m"
$gitbranch = ""
$us = ""
$ts = ""
if (Test-Path "$($executionContext.SessionState.Path.CurrentLocation)/.git")
{
$gitbranch = " $ESC[92m$(git rev-parse --abbrev-ref HEAD)$ESC[0m"
$gitstatus = $(& git status --porcelain)
$um = ($gitstatus | Select-String -pattern '^ M').Count
$ud = ($gitstatus | Select-String -pattern '^ D').Count
$uu = ($gitstatus | Select-String -pattern '^\?\?').Count
$tm = ($gitstatus | Select-String -pattern '^M').Count
$td = ($gitstatus | Select-String -pattern '^D').Count
$ta = ($gitstatus | Select-String -pattern '^A').Count
$ums = ($um -gt 0) ? " ~$um" : ""
$uds = ($ud -gt 0) ? " -$ud" : ""
$uus = ($uu -gt 0) ? " +$uu" : ""
$us = (($um + $ud + $uu) -gt 0) ? " $ESC[91m|$uus$ums$uds$ESC[0m" : ""
$tms = ($tm -gt 0) ? " ~$tm" : ""
$tds = ($td -gt 0) ? " -$td" : ""
$tas = ($ta -gt 0) ? " +$ta" : ""
$ts = (($tm + $td + $ta) -gt 0) ? " $ESC[93m|$tas$tms$tds$ESC[0m" : ""
}
"`r`n$($executionContext.SessionState.Path.CurrentLocation)$($gitbranch)$($us)$($ts)`r`n$($time) $('>' * ($nestedPromptLevel + 1)) ";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment