Skip to content

Instantly share code, notes, and snippets.

@cvn
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvn/9147832 to your computer and use it in GitHub Desktop.
Save cvn/9147832 to your computer and use it in GitHub Desktop.
Git Prompt
# original git prompt from ray
# http://raysohn.com/posts/simple-git-prompt.html
# Fix wrapping behavior (escape non-printing characters)
# http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/nonprintingchars.html
# Output escaped non-printing characters from a function
# http://stackoverflow.com/a/13997892/490592
# Maintain new tab behavior in Terminal.app
# http://superuser.com/a/623305/75328
simple_git_prompt () {
local branch="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
local git_info
if [ -n "$branch" ]
then
local red="\[\033[31m\]"
local green="\[\033[32m\]"
local reset="\[\033[0m\]"
if [ -n "$(git status -z 2> /dev/null)" ]
then
git_info="(${red}✘${reset} $branch) " # dirty index
else
git_info="(${green}✔${reset} $branch) " # clean index
fi
fi
PS1="\u@\h \W $git_info\$ "
}
PROMPT_COMMAND="simple_git_prompt; $PROMPT_COMMAND"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment