Skip to content

Instantly share code, notes, and snippets.

@fzaffa
Created January 3, 2016 20:48
Show Gist options
  • Save fzaffa/f5561124af279e2ed8e4 to your computer and use it in GitHub Desktop.
Save fzaffa/f5561124af279e2ed8e4 to your computer and use it in GitHub Desktop.
Bash Show Branch
IBlack='\e[0;90m' # Nero
IRed='\e[0;91m' # Rosso
IGreen='\e[0;92m' # Verde
IYellow='\e[0;93m' # Giallo
IBlue='\e[0;94m' # Blu
IPurple='\e[0;95m' # Viola
ICyan='\e[0;96m' # Ciano
IWhite='\e[0;97m' # Bianco
parse_git_branch() {
#git branch 2> /dev/null | grep '\*' | sed '/s(.+)/($1)'
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
branch_color() {
git branch &> /dev/null
if [ $? -ne 0 ] ; then
return
else
if git status 2> /dev/null | grep --quiet "nothing to commit" ; then
printf "\e[0;94m"
else
printf "\e[0;91m"
fi
fi
}
PS1="\[$IGreen\]\u \[$ICyan\][\w]\[\$(branch_color)\]\$(parse_git_branch)\[$IWhite\] \n → "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment