Skip to content

Instantly share code, notes, and snippets.

@martinos
Created January 20, 2010 05:45
Show Gist options
  • Save martinos/281638 to your computer and use it in GitHub Desktop.
Save martinos/281638 to your computer and use it in GitHub Desktop.
# ---------
# Prompt
# ---------
function gitprompt {
blue='\[\e[0;34;1m\]'
red='\[\e[0;38;1m\]'
green='\[\e[0;32;1m\]'
none='\[\e[0m\]'
prompt_info=""
leftbracket=""
rightbracket=""
if [ $(($(git diff --cached --name-only 2> /dev/null | wc -l) )) -gt 0 ]; then
prompt_info+=" ${green}*${none}"
fi
if [ $(($(git diff --name-only 2> /dev/null | wc -l) )) -gt 0 ]; then
prompt_info+=" ${red}*${none}"
fi
if [ $(($(git ls-files --other --exclude-standard 2> /dev/null | wc -l) )) -gt 0 ]; then
prompt_info+=" ${red}-${none}"
fi
if [ $(($(git status 2> /dev/null| grep "Your branch is ahead of" | wc -l) )) -gt 0 ]; then
prompt_info+=" ${blue}*${none}"
fi
branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/")
if [ -n "$branch" ]; then
leftbracket="["
rightbracket="]"
fi
begining='[\j] \[\033[035;40m\]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
export PS1="$begining$leftbracket$branch$prompt_info$rightbracket$ "
}
PROMPT_COMMAND=gitprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment