Created
August 13, 2011 22:44
-
-
Save yujiberra/1144329 to your computer and use it in GitHub Desktop.
Bash profile with color current git branch color coded by status
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
# Git status bash prompt | |
# | |
# In addition to printing the current working directory, this prompt will | |
# show a number of things if you are in a git repository: | |
# - The current branch you are in | |
# - Whether there are untracked files in the repository (there will be an | |
# asterisk after the branch nome if there are) | |
# - Whether there are any unmerged/unstaged/staged changes or if the directory | |
# is clean. See below for the colors that will be used, and change them if | |
# you'd like. | |
# Storing these color codes for later use | |
txtblk='\033[0;30m' # Black - Regular | |
txtred='\033[0;31m' # Red | |
txtgrn='\033[0;32m' # Green | |
txtylw='\033[0;33m' # Yellow | |
txtblu='\033[0;34m' # Blue | |
txtpur='\033[0;35m' # Purple | |
txtcyn='\033[0;36m' # Cyan | |
bldblk='\033[1;30m' # Black - Bold | |
bldred='\033[1;31m' # Red | |
bldgrn='\033[1;32m' # Green | |
bldylw='\033[1;33m' # Yellow | |
bldblu='\033[1;34m' # Blue | |
bldpur='\033[1;35m' # Purple | |
bldcyn='\033[1;36m' # Cyan | |
# Set color for the directory listing in the prompt | |
dir_listing_color=$bldgrn | |
# Set colors for different repository states | |
unmerged_color=$bldpur | |
unstaged_color=$bldred | |
staged_color=$bldcyn | |
clean_color=$bldblu | |
function git_color { | |
git_status=`git status 2> /dev/null` | |
if [ -n "`echo $git_status | grep "# Unmerged paths:"`" ]; then | |
echo -e $unmerged_color | |
elif [ -n "`echo $git_status | grep "# Changes not staged for commit:"`" ]; then | |
echo -e $unstaged_color | |
elif [ -n "`echo $git_status | grep "# Changes to be committed:"`" ]; then | |
echo -e $staged_color | |
else | |
echo -e $clean_color | |
fi | |
} | |
function git_branch { | |
git_branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
if [ -n "`git status 2> /dev/null | grep "# Untracked files:"`" ]; then | |
untracked="*" | |
fi | |
if [ "`expr "$git_branch" : '.*'`" -gt "0" ]; then | |
echo \($git_branch$untracked\) | |
fi | |
} | |
PS1='\[`echo -e $dir_listing_color`\]\w \[`git_color`\]`git_branch` \[\e[0m\]$ ' | |
PS2="> " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment