Skip to content

Instantly share code, notes, and snippets.

@wojtha
Forked from markembling/profile.ps1
Created June 19, 2011 10:18
Show Gist options
  • Save wojtha/1034041 to your computer and use it in GitHub Desktop.
Save wojtha/1034041 to your computer and use it in GitHub Desktop.
My preferred prompt for Powershell - includes git info.
# My preferred prompt for Powershell.
# Displays git branch and stats when inside a git repository.
# See http://gist.github.com/180853 for gitutils.ps1.
. (Resolve-Path ~/Documents/WindowsPowershell/gitutils.ps1)
function prompt {
$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
if (isCurrentDirectoryGitRepository) {
$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
}
Write-Host('>') -nonewline -foregroundcolor Green
return " "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment