Last active
August 29, 2015 13:56
-
-
Save cvn/9147832 to your computer and use it in GitHub Desktop.
Git Prompt
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
# 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