Skip to content

Instantly share code, notes, and snippets.

@bernd
Forked from railsdog/gist:58158
Created February 4, 2009 20:27
Show Gist options
  • Save bernd/58327 to your computer and use it in GitHub Desktop.
Save bernd/58327 to your computer and use it in GitHub Desktop.
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*
"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
}
function git_prompt {
local dirty=$(parse_git_dirty)
local branch=$(parse_git_branch)
local color="32"
[[ "$dirty" = "*" ]] && color="33"
PS1="\h:\W\[\033[0;${color}m\][${branch}${dirty}]\[\e[0m\]$ "
}
export PROMPT_COMMAND=git_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment