Created
July 15, 2013 18:56
-
-
Save alexey/6002435 to your computer and use it in GitHub Desktop.
Colored bash prompt with current git branch name, also color git branch name if code changed.
Put it under ur HOME folder with ".bashrc" name
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
# Configure colors here | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
c_reset='\[\e[0m\]' | |
c_user='\[\033[1;35m\]' | |
c_path='\[\e[1;34m\]' | |
c_git_clean='\[\e[1;32m\]' | |
c_git_dirty='\[\e[1;31m\]' | |
else | |
c_reset= | |
c_user= | |
c_path= | |
c_git_clean= | |
c_git_dirty= | |
fi | |
git_prompt () | |
{ | |
if ! git rev-parse --git-dir > /dev/null 2>&1; then | |
return 0 | |
fi | |
git_branch=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
if git diff --quiet 2>/dev/null >&2; then | |
git_color="$c_git_clean" | |
else | |
git_color="$c_git_dirty" | |
fi | |
echo " [$git_color$git_branch${c_reset}]" | |
} | |
# Customize look here | |
PROMPT_COMMAND='PS1="${c_user}\u${c_reset}@${c_user}\h${c_reset}:${c_path}\w${c_reset}$(git_prompt)\$ "' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment