Created
August 15, 2010 14:53
-
-
Save thlorenz/525571 to your computer and use it in GitHub Desktop.
Svn/Git PowerShell prompt
This file contains 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
# See http://gist.github.com/180853 for gitutils.ps1. | |
. (Resolve-Path ~/Documents/WindowsPowershell/gitutils.ps1) | |
function prompt { | |
writeUserLocation | |
if (isCurrentDirectoryGitRepository) { | |
writeGitInfo | |
} | |
elseif(Test-Path .svn) { | |
writeSvnInfo | |
} | |
Write-Host("`n$") -nonewline -foregroundcolor Green | |
return " " | |
} | |
function writeUserLocation { | |
Write-Host($pwd) -nonewline -foregroundcolor Green | |
} | |
function writeShortenedUserLocation { | |
$path = "" | |
$pathbits = ([string]$pwd).split("\", [System.StringSplitOptions]::RemoveEmptyEntries) | |
if($pathbits.length -eq 1) { | |
$path = $pathbits[0] + "\" | |
} else { | |
$path = $pathbits[$pathbits.length - 1] | |
} | |
$userLocation = $env:username + '@' + [System.Environment]::MachineName + ' ../' + $path | |
$host.UI.RawUi.WindowTitle = $userLocation | |
Write-Host($userLocation) -nonewline -foregroundcolor Green | |
} | |
function writeGitInfo { | |
$status = gitStatus | |
$currentBranch = $status["branch"] | |
Write-Host(' [') -nonewline -foregroundcolor Yellow | |
if ($status["ahead"] -eq $FALSE) { | |
# We are not ahead of origin | |
Write-Host($currentBranch) -nonewline -foregroundcolor Cyan | |
} else { | |
# We are ahead of origin | |
Write-Host($currentBranch) -nonewline -foregroundcolor Red | |
} | |
Write-Host(' +' + $status["added"]) -nonewline -foregroundcolor Yellow | |
Write-Host(' ~' + $status["modified"]) -nonewline -foregroundcolor Yellow | |
Write-Host(' -' + $status["deleted"]) -nonewline -foregroundcolor Yellow | |
if ($status["untracked"] -ne $FALSE) { | |
Write-Host(' !') -nonewline -foregroundcolor Yellow | |
} | |
Write-Host(']') -nonewline -foregroundcolor Yellow | |
} | |
function writeSvnInfo { | |
$untracked=$deleted=$added=$modified=0 | |
switch -regex (svn st) { | |
"^\?" {$untracked+=1} | |
"^D" {$deleted+=1} | |
"^A" {$added+=1} | |
"^M" {$modified+=1} | |
} | |
$prompt_string = " [svn +$added ~$modified -$deleted" | |
if ($untracked -eq 0) { | |
$prompt_string += "]" | |
} | |
else { | |
$prompt_string += " !]" | |
} | |
Write-Host ($prompt_string) -nonewline -foregroundcolor yellow | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment