Skip to content

Instantly share code, notes, and snippets.

@miraculixx
Last active December 26, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miraculixx/7082949 to your computer and use it in GitHub Desktop.
Save miraculixx/7082949 to your computer and use it in GitHub Desktop.
print the currently active git branch as part of the prompt
## (c) miraculixx 2013
##
## PROVIDED WITH NO WARRANTY OF ANY KIND. NOT FIT FOR PRODUCTION USE.
##
## add this to your ~/.bashrc
## if there is an active git repository in the current directory
## your prompt will show as (branch)$PS1
## where "branch" is the name of the currently active git branch and $PS1 is your normal print
## branch will be printed in green. Change the 1;32 part of the prompt to show a different color (e.g. 1;31 = red)
# show active git branch
gb() {
# >nul will ignore any error messages
# printf will print this without a new line
git branch 2>/dev/null | grep "*" | awk '{ printf "(\033[1;32m%s\033[0m)",$2}'
}
# activate git branch display for any git repository
export PROMPT_COMMAND=gb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment