Skip to content

Instantly share code, notes, and snippets.

@wdicarlo
Created September 9, 2014 06:45
Show Gist options
  • Save wdicarlo/2d2868850bc95709b91a to your computer and use it in GitHub Desktop.
Save wdicarlo/2d2868850bc95709b91a to your computer and use it in GitHub Desktop.
# This script, whose origin has been lost, will output the current branch and change status in your bash prompt.
# See http://www.incaseofstairs.com/2013/01/osx-frontend-toolchain/
#
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
function last_two_dirs {
pwd |rev| awk -F / '{print $1,$2}' | rev | sed s_\ _/_
}
c_cyan=`tput setaf 6`
c_red=`tput setaf 1`
c_green=`tput setaf 2`
c_sgr0=`tput sgr0`
function proml {
PS1='\h:$(last_two_dirs)\[$(branch_color)\]$(parse_git_branch)\[${c_sgr0}\] \u\$ '
}
function branch_color() {
if git rev-parse --git-dir >/dev/null 2>&1
then
color=""
git diff --quiet 2>/dev/null >&2
if [[ $? -eq 0 ]]
then
color=${c_cyan}
else
color=${c_red}
fi
else
return 0
fi
echo -ne $color
}
proml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment