Skip to content

Instantly share code, notes, and snippets.

@fadhlirahim
Last active December 16, 2015 09:19
Show Gist options
  • Save fadhlirahim/5412518 to your computer and use it in GitHub Desktop.
Save fadhlirahim/5412518 to your computer and use it in GitHub Desktop.
Show current git branch with color
GREEN="\[\033[0;32m\]"
WHITE="\[\033[1;37m\]"
# Get the name of the current git branch
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# Update the command prompt to be <current_directory>(git_branch) >
# Note that the git branch is given a special color
function set_my_prompt {
PS1="\w$GREEN\$(parse_git_branch)$WHITE\$ "
}
set_my_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment