Last active
December 26, 2015 02:59
-
-
Save miraculixx/7082949 to your computer and use it in GitHub Desktop.
print the currently active git branch as part of the prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## (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