Skip to content

Instantly share code, notes, and snippets.

@marclipovsky
Created September 6, 2012 19:10
Show Gist options
  • Save marclipovsky/3659594 to your computer and use it in GitHub Desktop.
Save marclipovsky/3659594 to your computer and use it in GitHub Desktop.
Include branch name (and other info) in my bash prompt
# Get's the current git branch
function parse_git_branch
{
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo "("${ref#refs/heads/}")"
}
# Checks to see if there are uncommitted files
function git_status
{
string=$(git status 2> /dev/null) || return
if [[ "$string" == *"Changes not staged for commit"* ]]
then
echo "!"
fi
}
# Checks to see if there are files ready to be committed
function git_changes
{
string=$(git status 2> /dev/null) || return
if [[ "$string" == *"Changes to be committed"* ]]
then
echo "+"
fi
}
RED="\[\e[0;31m\]"
YELLOW='\[\e[0;33m\]'
CYAN='\[\e[0;36m\]'
WHITE='\[\e[0;37m\]'
GREEN='\[\e[0;32m\]'
PS1="$RED ➜ $CYAN\W $YELLOW\$(parse_git_branch)$RED\$(git_status)$GREEN\$(git_changes) $WHITE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment