Skip to content

Instantly share code, notes, and snippets.

@dsibilly
Created July 3, 2012 00:30
Show Gist options
  • Save dsibilly/3036625 to your computer and use it in GitHub Desktop.
Save dsibilly/3036625 to your computer and use it in GitHub Desktop.
Add git branch info to your prompt (only in git-controlled directories!)
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working direct
ory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(par
se_git_dirty)]/"
}
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
RESET="\[\033[0;0m\]"
PS1="$RED\h:\W$YELLOW \$(parse_git_branch)$GREEN\$$RESET "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment