Created
June 6, 2013 15:58
-
-
Save agarzon/5722643 to your computer and use it in GitHub Desktop.
Coloured Git Status in Your Bash 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
# User specific aliases and functions | |
function _git_prompt() { | |
local git_status="`git status -unormal 2>&1`" | |
if ! [[ "$git_status" =~ Not\ a\ git\ repo ]]; then | |
if [[ "$git_status" =~ nothing\ to\ commit ]]; then | |
local ansi=32 | |
elif [[ "$git_status" =~ nothing\ added\ to\ commit\ but\ untracked\ files\ present ]]; then | |
local ansi=34 | |
else | |
local ansi=33 | |
fi | |
echo -n '\[\e[0;33;'"$ansi"'m\]'"$(__git_ps1)"'\[\e[0m\]' | |
fi | |
} | |
function _prompt_command() { | |
PS1="[\[\033[32m\]\w\[\033[0m\]]\[\033[0m\]\n\[\033[1;36m\]\u@\[\033[0;37m\]\h] `_git_prompt` \[\033[1;33m\]: \[\033[0m\]" | |
} | |
PROMPT_COMMAND=_prompt_command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add the code in .bashrc or .bash_profile