place this in ~/.bashrc
or ~/.bash_profile
_pretty_prompt() {
# args: $maincolor_int, $dircolor_int, $gitcolor_int, $style_str
# color ints: green 32, yellow 33, cyan 36, white 37, reset(none) 00
# style: '1;2;4;' means bold dim and underline. leave off for no style
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
# GIT_PS1_SHOWDIRTYSTATE=true
# abbrevates path to show only directory and parent directory,
# showing ~ symbol if appropriate:
PROMPT_COMMAND='case $PWD in
$HOME) HPWD="~";;
$HOME/*/*) HPWD="${PWD#"${PWD%/*/*}/"}";;
$HOME/*) HPWD="~/${PWD##*/}";;
/*/*/*) HPWD="${PWD#"${PWD%/*/*}/"}";;
*) HPWD="$PWD";;
esac'
_git_nfo() {
git status >/dev/null 2>&1;
if [ $? -eq 0 ]; then
local gitstatus=$(git status 2> /dev/null)
local repo=$(basename $(git rev-parse --show-toplevel))
local branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
local marker=''
if [[ `echo $gitstatus | grep "nothing to commit"` != "" ]]; then marker=''
elif [[ `echo $gitstatus | grep "Changes to be committed"` != "" ]];then marker='***'
elif [[ `echo $gitstatus | grep "Changes not staged"` != "" ]]; then marker='**'
elif [[ `echo $gitstatus | grep "Untracked"` != "" ]]; then marker='*'
else marker='?'
fi
echo " ($repo $branch$marker)";
else echo "";
fi
}
[ "$SSH_CONNECTION" ] && local userhost='\u@\h' || local userhost='\u'
local C='\[\033['$4 # color start
local E='m\]' # color end
export PS1="$C$1$E$userhost$C$2$E "'$HPWD'$C$3$E'$(_git_nfo)\n'$C$1$E\$$C"00$E "
}
_pretty_prompt 36 33 36 '1;2;4;' # see function def for args explanation