Skip to content

Instantly share code, notes, and snippets.

@rkeithhill
Last active February 26, 2023 19:27
Show Gist options
  • Save rkeithhill/7585749cec4f4fc83fc964c88bb252ef to your computer and use it in GitHub Desktop.
Save rkeithhill/7585749cec4f4fc83fc964c88bb252ef to your computer and use it in GitHub Desktop.
Config file for posh-git.
# Import Posh-Git and configure Git prompt
Import-Module posh-git
#Import-Module ~\GitHub\dahlbyk\posh-git\src\posh-git.psd1
#Import-Module ~\GitHub\dahlbyk\posh-git\out\posh-git\1.0.0\posh-git.psd1
# Windows PowerShell doesn't parse `e or `u escape sequences in DQ strings. I added that support to the PS parser in 6.0
if ($PSVersionTable.PSVersion.Major -lt 6) {
$global:GitPromptSettings.WindowTitle = {
param($GitStatus, [bool]$IsAdmin)
"WinPS $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) ($PID)"
}
return
}
function global:PromptWriteErrorInfo() {
# For an error indicator, use 🔥 in Windows Terminal and a red ! elsewhere
$errIndicator = if (Test-Path Env:\WT_SESSION) { "`u{1f525}" } else { "!" }
$exitCode = $global:GitPromptValues.LastExitCode
if ($exitCode -and !$global:GitPromptValues.DollarQuestion) {
if ($exitCode -le -16KB) {
$exitCode = "0x{0:X8}" -f $exitCode
}
"`e[31m${errIndicator}${exitCode} `e[0m"
}
elseif (!$global:GitPromptValues.DollarQuestion) {
"`e[31m${errIndicator}"
}
}
function global:PromptWriteTime() {
"`e[38;2;127;127;127m" + [DateTime]::now.ToString("MM-dd HH:mm:ss") + "`e[0m"
}
$global:GitPromptSettings.DefaultPromptEnableTiming = $false
if (Test-Path Env:\WT_SESSION) {
# These settings require the Cascadia Code/Mono PL font from https://github.com/microsoft/cascadia-code/releases
$BranchSymbol = "`u{e0a0}"
$EndCapRight = "`u{e0b0}"
$BlackRbg = "0;0;0" # "40;44;52"
$BlueRgb = "0;122;204"
$DarkGrayRgb = "90;99;116"
$DarkGreenRgb = "0;96;0"
$DarkMagentaRgb = "192;0;192"
$DarkYellowRgb = "229;192;122"
$GreenRgb = "0;106;78"
$RedRgb = "128;24;24"
$WhiteRgb = "232;232;232" # "220;223;228"
$BlackFg = "`e[38;2;${BlackRbg}m"
$BlueBg = "`e[48;2;${BlueRgb}m"
$BlueFg = "`e[38;2;${BlueRgb}m"
$DarkGrayBg = "`e[48;2;${DarkGrayRgb}m"
$DarkGreenFg = "`e[38;2;${DarkGreenRgb}m"
$DarkMagentaFg = "`e[38;2;${DarkMagentaRgb}m"
$DarkYellowBg = "`e[48;2;${DarkYellowRgb}m"
$GreenBg = "`e[48;2;${GreenRgb}m"
$RedBg = "`e[48;2;${RedRgb}m"
$RedFg = "`e[38;2;${RedRgb}m"
$WhiteFg = "`e[38;2;${WhiteRgb}m"
$PathBg = $BlueBg
$PathFg = $WhiteFg
$BranchBg = $DarkYellowBg
$BranchFg = $BlackFg
$StatusFg = $WhiteFg
$StashBg = $DarkGrayBg
$StashFg = $WhiteFg
# We don't have "fixed-width" tabs in Windows Terminal yet, so limit the info displayed so the tabs
# don't get too wide.
$global:GitPromptSettings.WindowTitle = {
param($GitStatus, [bool]$IsAdmin)
"$(if ($IsAdmin) {'Admin: '})PS $($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) ($PID)"
}
$global:GitPromptSettings.EnableStashStatus = $false # enabling this adds ~150 ms to prompt generation time
$global:GitPromptSettings.DefaultPromptWriteStatusFirst = $false
$global:GitPromptSettings.DefaultPromptPath.BackgroundColor = $PathBg
$global:GitPromptSettings.DefaultPromptPath.ForegroundColor = $PathFg
if ($global:GitPromptSettings.DefaultPromptWriteStatusFirst) {
$global:GitPromptSettings.BeforeStatus.Text = " ${BranchSymbol}"
}
else {
$global:GitPromptSettings.BeforeStatus.Text = "`e[1D${BlueFg}${EndCapRight}${BlackFg}${BranchSymbol}"
}
$global:GitPromptSettings.BeforeStatus.BackgroundColor = $BranchBg
$global:GitPromptSettings.BeforeStatus.ForegroundColor = $BranchFg
$global:GitPromptSettings.BranchColor.BackgroundColor = $BranchBg
$global:GitPromptSettings.BranchColor.ForegroundColor = $BranchFg
$global:GitPromptSettings.BranchAheadStatusSymbol.BackgroundColor = $BranchBg
$global:GitPromptSettings.BranchAheadStatusSymbol.ForegroundColor = $DarkGreenFg
$global:GitPromptSettings.BranchBehindStatusSymbol.BackgroundColor = $BranchBg
$global:GitPromptSettings.BranchBehindStatusSymbol.ForegroundColor = $RedFg
$global:GitPromptSettings.BranchBehindAndAheadStatusSymbol.BackgroundColor = $BranchBg
$global:GitPromptSettings.BranchBehindAndAheadStatusSymbol.ForegroundColor = $DarkMagentaFg
$global:GitPromptSettings.BeforeIndex.Text = ' '
$global:GitPromptSettings.BeforeIndex.BackgroundColor = $BranchBg
$global:GitPromptSettings.IndexColor.BackgroundColor = $GreenBg
$global:GitPromptSettings.IndexColor.ForegroundColor = $StatusFg
$global:GitPromptSettings.DelimStatus.Text = ' '
$global:GitPromptSettings.WorkingColor.BackgroundColor = $RedBg
$global:GitPromptSettings.WorkingColor.ForegroundColor = $StatusFg
$global:GitPromptSettings.ErrorColor.BackgroundColor = $RedBg
$global:GitPromptSettings.ErrorColor.ForegroundColor = $StatusFg
$global:GitPromptSettings.LocalWorkingStatusSymbol.Text = '! '
$global:GitPromptSettings.LocalWorkingStatusSymbol.ForegroundColor = $StatusFg
$global:GitPromptSettings.LocalStagedStatusSymbol.Text = '~ '
$global:GitPromptSettings.LocalStagedStatusSymbol.ForegroundColor = $StatusFg
$global:GitPromptSettings.BeforeStash.Text = ' '
$global:GitPromptSettings.BeforeStash.BackgroundColor = $StashBg
$global:GitPromptSettings.BeforeStash.ForegroundColor = $StashFg
$global:GitPromptSettings.StashColor.BackgroundColor = $StashBg
$global:GitPromptSettings.StashColor.ForegroundColor = $StashFg
$global:GitPromptSettings.AfterStash.Text = ' '
$global:GitPromptSettings.AfterStash.BackgroundColor = $StashBg
$global:GitPromptSettings.AfterStash.ForegroundColor = $StashFg
if ($global:GitPromptSettings.DefaultPromptWriteStatusFirst) {
# Set bg to BranchBg for a space, then swap bg/fg and set fg (really the bg) to blue for end cap symbol
$global:GitPromptSettings.AfterStatus.Text = "${BranchBg}`e[7m${BlueFg}${EndCapRight}"
}
else {
$global:GitPromptSettings.AfterStatus.Text = "${BranchBg}`e[49m${EndCapRight}"
}
# Either set the path status sep to an empty string, of if a space, set bg color to path bg color
$global:GitPromptSettings.PathStatusSeparator.Text = ''
#$global:GitPromptSettings.PathStatusSeparator.BackgroundColor = $PathBg
# If ~ in path, replace it with house emoji symbol 🏠
$global:GitPromptSettings.DefaultPromptPath.Text = '$((Get-PromptPath) -replace "^~","`u{1f3e0}")`e[38;2;0;122;204m`e[49m`u{e0b0}'
}
else {
$global:GitPromptSettings.DefaultPromptWriteStatusFirst = $true
$global:GitPromptSettings.DefaultPromptPath.BackgroundColor = "`e[48;2;0;122;204m"
$global:GitPromptSettings.DefaultPromptPath.ForegroundColor = [System.ConsoleColor]::White
$global:GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [System.ConsoleColor]::Yellow
}
$global:GitPromptSettings.DefaultPromptAbbreviateGitDirectory = $true
$global:GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`e[0m`n$(PromptWriteErrorInfo)$(PromptWriteTime)'
$global:GitPromptSettings.DefaultPromptSuffix.Text = ' $((Get-History -Count 1).id + 1)$(">" * ($nestedPromptLevel + 1)) '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment