Created
January 21, 2025 08:37
-
-
Save Vlasterx/48fcaf0df36e999883c15040915aed63 to your computer and use it in GitHub Desktop.
Minimal git prompt for Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add this to Powershell profile | |
| function prompt { | |
| $gitBranch = & git rev-parse --abbrev-ref HEAD 2>$null | |
| $pathString = "$PWD" | |
| $gitString = "" | |
| if ($gitBranch) { | |
| $status = & git status -sb 2>$null | |
| $aheadBehind = "" | |
| $uncommittedChanges = $false | |
| $color = "Green" | |
| if ($status -match "\[ahead (\d+)\]") { | |
| $aheadBehind += "↑$($matches[1])" | |
| } | |
| if ($status -match "\[behind (\d+)\]") { | |
| $aheadBehind += "↓$($matches[1])" | |
| } | |
| if ($status -match "^\s*[^#]") { | |
| $uncommittedChanges = $true | |
| $color = "Yellow" | |
| } | |
| if ($aheadBehind) { | |
| $gitString = " ($gitBranch $aheadBehind)" | |
| } else { | |
| $gitString = " ($gitBranch)" | |
| } | |
| if ($uncommittedChanges) { | |
| $gitString += "*" | |
| } | |
| # Apply color to git part | |
| if ($color -eq "Yellow") { | |
| $gitString = "`e[0;33m$gitString`e[0m" # Yellow for git part | |
| } else { | |
| $gitString = "`e[0;32m$gitString`e[0m" # Green for git part | |
| } | |
| } | |
| # Apply color to path part | |
| $pathString = "`e[0;34m$pathString`e[0m" # Blue for path | |
| $currentTime = Get-Date -Format "HH:mm:ss" | |
| "`n$currentTime $pathString$gitString`n> " | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment