Skip to content

Instantly share code, notes, and snippets.

@trevmex
Created July 24, 2012 15:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevmex/3170548 to your computer and use it in GitHub Desktop.
Save trevmex/3170548 to your computer and use it in GitHub Desktop.
Add git messaging to your bash prompt
#
# Colors
#
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NORMAL="\[\033[0m\]"
#
# Prompt Setup
#
function parse_git_in_rebase {
[[ -d .git/rebase-apply ]] && echo " REBASING"
}
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
branch=$(git branch 2> /dev/null | grep "*" | sed -e s/^..//g)
if [[ -z ${branch} ]]; then
return
fi
echo " ("${branch}$(parse_git_dirty)$(parse_git_in_rebase)")"
}
export PS1="$RED\u@\h:$GREEN\W$YELLOW\$(parse_git_branch)$NORMAL\$ " # Add git info to the prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment