Skip to content

Instantly share code, notes, and snippets.

@aristidb
Created April 16, 2009 14:58
Show Gist options
  • Select an option

  • Save aristidb/96455 to your computer and use it in GitHub Desktop.

Select an option

Save aristidb/96455 to your computer and use it in GitHub Desktop.
function Get-GitBranchNameWithStatusIndicator {
$statusOutput = Invoke-Expression 'git status 2>$null'
if (!$statusOutput) { return }
$branch = $statusOutput[0]
if ($branch -eq "# Not currently on any branch.") {
$branch = "No branch"
} else {
$branch = $branch.SubString("# On branch ".Length)
}
$statusSummary = $statusOutput[-1]
if ($statusSummary -eq "nothing to commit (working directory clean)") {
$statusIndicator = ""
} else {
$statusIndicator = "*"
}
return $branch + $statusIndicator
}
function prompt {
$location = (Get-Location).ToString()
$shortLocation = $location.Replace($HOME, "~")
$gitStatus = Get-GitBranchNameWithStatusIndicator
Write-Host ("PS " + $shortLocation) -nonewline
$host.ui.rawui.WindowTitle = $location
if ($gitStatus) {
Write-Host (" [" + $gitStatus +"]") -nonewline -foregroundcolor Gray
$host.ui.rawui.WindowTitle += (" [" + $gitStatus +"]")
}
Write-Host (">") -nonewline
$host.ui.rawui.WindowTitle += " - PowerShell"
return " "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment