Skip to content

Instantly share code, notes, and snippets.

@KalikaKay
Forked from githubteacher/show-branch.md
Last active May 13, 2016 19:39
Show Gist options
  • Save KalikaKay/c127558d36420e27023cffe5eea73943 to your computer and use it in GitHub Desktop.
Save KalikaKay/c127558d36420e27023cffe5eea73943 to your computer and use it in GitHub Desktop.
Add your Git branch to your command prompt, adjust font or colors.

To show your active Git branch in your command prompt, you will need to do the following:

  • If you are on a Mac, you can add the code shown below to your .bash_profile file.
  • If you are on Linux, you will add the code shown below to the end of your .bashrc file.
  • If you are on Windows, you probably aren't reading this because Windows provides this behavior by default.

Option I:

######Uncomment force_color_prompt=yes######

#Parse and display the git branch.
function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

HC="\[\033[1m\]"
LC="\[\033[2m\]"
IT="\[\033[3m\]"
PINK="\[\033[038;5;218m\]"
CYAN="\[\033[36m\]"
NO_COLOR="\[\033[0m\]"
KEEPHER="\[\033]12;#ffafd7\a\]"
#CURSOR="\[\033]12;pink\a\]"

#PS1="$PS1$HC$IT$CYAN\$(parse_git_branch)$NO_COLOR "
PS1="$PS1$HC$IT$CYAN\$(parse_git_branch)$NO_COLOR$PINK$KEEPHER "

Option II

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\w\[\033[36m\]\$(parse_git_branch) \[\033[00m\] > "

Option III:

function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
 
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
 
PS1="$GREEN\u@\h$NO_COLOR:\w$YELLOW\$(parse_git_branch)$NO_COLOR\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment