-
-
Save brenes/1024938 to your computer and use it in GitHub Desktop.
Color current git branch in prompt
This file contains hidden or 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
| # Color the current git branch in prompt | |
| # red -> we are in master, take care! | |
| # blue -> just a normal branch. Carry on | |
| function __colorize_git_ps1 () { | |
| local branch=$(__git_ps1 "%s") | |
| if [ -n "$branch" ]; then | |
| local color | |
| if [[ $branch == master* ]]; then | |
| color="31" #Red | |
| fi | |
| if [[ $branch == dev* ]]; then | |
| color="32" #Green | |
| fi | |
| if [[ $branch == features* ]]; then | |
| color="36" #Blue | |
| fi | |
| if [[ $branch == fix* ]]; then | |
| color="35" #Light Red | |
| fi | |
| printf "[\e[${color}m${branch}\e[0m]" | |
| fi | |
| } | |
| GIT_PS1_SHOWDIRTYSTATE=t | |
| PS1='\w$(__colorize_git_ps1)\$ ' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment