Skip to content

Instantly share code, notes, and snippets.

@Hiteshm01
Created February 8, 2015 17:12
Show Gist options
  • Save Hiteshm01/b1a189259a0bb75d7dc1 to your computer and use it in GitHub Desktop.
Save Hiteshm01/b1a189259a0bb75d7dc1 to your computer and use it in GitHub Desktop.
git branch name in bashrc
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
bold=$(tput bold)
reset=$(tput sgr0)
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != 'nothing to commit (working directory clean)' ]] && echo $red || echo $green
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/\* \(.*\)/\1/"
}
if [ "$color_prompt" = yes ]; then
PS1="\[$bold\]\[$yellow\]\h\[$reset\]:\[$bold\]\[$blue\]\w\[$reset\]:\[\$(parse_git_dirty)\]\$(parse_git_branch)\[\$reset\]\$ "
else
PS1='\u@\h:\W:$(parse_git_branch) " (%s)")\$ '
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment