Skip to content

Instantly share code, notes, and snippets.

@markalanevans
Last active September 27, 2015 11:58
Show Gist options
  • Select an option

  • Save markalanevans/1266363 to your computer and use it in GitHub Desktop.

Select an option

Save markalanevans/1266363 to your computer and use it in GitHub Desktop.
A Git Prompt which adds the branch you are on to the prompt.
#Description: OSX Git Prompt - make your git repo prompts look pretty
#Installation: In your .bash_profile, add a line: source .gitprompt
#FileName: .gitprompt
#Owner: Mark Evans:
#Stolen From: http://asemanfar.com/Current-Git-Branch-in-Bash-Prompt
#also install git complet: brew install git bash-completion
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
parse_git_branch ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')
else
return 0
fi
echo -e $gitver
}
branch_color ()
{
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
if git diff --quiet 2>/dev/null >&2
then
color="${c_green}"
else
color=${c_red}
fi
else
return 0
fi
echo -ne $color
}
#Branch First
#PS1='[\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]] \u@\[${c_red}\]\w\[${c_sgr0}\]:'
#Branch Last
PS1=' \u@\[${c_red}\]\w\[${c_sgr0}\]: [\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\]]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment