Skip to content

Instantly share code, notes, and snippets.

@rocketraman
Created December 21, 2011 00:53
Show Gist options
  • Save rocketraman/1504026 to your computer and use it in GitHub Desktop.
Save rocketraman/1504026 to your computer and use it in GitHub Desktop.
UNIX Prompt setup with user@host, working directory, and git branch, git dirty, and git stash
function parse_git_dirty {
git symbolic-ref HEAD > /dev/null 2>&1 || return
git status 2> /dev/null | grep -q "nothing to commit" || echo "[d]"
}
function parse_git_stash {
git symbolic-ref HEAD > /dev/null 2>&1 || return
[[ $(git stash list 2> /dev/null | tail -n1) != "" ]] && echo "[s]"
}
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo " ${ref#refs/heads/}"
}
case $TERM in
xterm*)
#TITLEBAR='\[\e]0;\w\a\]'
# turn off titlebar temporarily, doesn't always work well
TITLEBAR=''
;;
*)
TITLEBAR=''
;;
esac
if [ "$TERM" != "dumb" ]; then
GRN="\[\e[32m\]"
YLW="\[\e[33m\]"
BLU="\[\e[1;34m\]"
PNK="\[\e[35m\]"
NOc="\[\033[0m\]"
PS1="${TITLEBAR}\n$GRN\u$NOc@$GRN\h $YLW\w$BLU\$(parse_git_branch)$PNK\$(parse_git_dirty)\$(parse_git_stash) $YLW\$$NOc "
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment