Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Just parses the git command output for a swanky prompt
# when in a git directory, outputs:
# GIT [branch] +# ~# -# | C:\my\path
# when in any other directory, outputs:
# PS C:\my\other\path
function prompt {
Write-Host("")
$status_string = ""
# check to see if this is a directory containing a symbolic reference,
# fails (gracefully) on non-git repos.
$symbolicref = git symbolic-ref HEAD
if($symbolicref -ne $NULL) {
# if a symbolic reference exists, snag the last bit as our
# branch name. eg "[master]"
$status_string += "GIT [" + `
$symbolicref.substring($symbolicref.LastIndexOf("/") +1) + "] "
# grab the differences in this branch
$differences = (git diff-index --name-status HEAD)
# use a regular expression to count up the differences.
# M`t, A`t, and D`t refer to M {tab}, etc.
$git_update_count = [regex]::matches($differences, "M`t").count
$git_create_count = [regex]::matches($differences, "A`t").count
$git_delete_count = [regex]::matches($differences, "D`t").count
# place those variables into our string.
$status_string += "+" + $git_create_count + `
" ~" + $git_update_count + `
" -" + $git_delete_count + " | "
}
else {
# Not in a Git environment, must be PowerShell!
$status_string = "PS "
}
# write out the status_string with the approprate color.
# prompt is done!
if ($status_string.StartsWith("GIT")) {
Write-Host ($status_string + $(get-location)) -foregroundcolor yellow
Write-Host "$ " -foregroundcolor white -nonewline
}
else {
Write-Host ($status_string + $(get-location)) -foregroundcolor green
Write-Host "$ " -foregroundcolor white -nonewline
}
return " "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.