Skip to content

Instantly share code, notes, and snippets.

@jlee42
Forked from peterwongpp/gist:2994714
Created July 6, 2012 19:00
Show Gist options
  • Save jlee42/3062087 to your computer and use it in GitHub Desktop.
Save jlee42/3062087 to your computer and use it in GitHub Desktop.
My Shell Command Line Format - colored, with Git support and shortened
# return the current git branch name
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ →\ \1/'
}
# return the string of state of the branch
parse_git_dirty() {
D="$(git status 2> /dev/null | tail -n1 | awk '{ print $1 }' )"
if [ "$D" = "nothing" ] ; then
echo -e "(clean) "
elif [ "$D" = "no" ]; then
echo -e "(modified) "
elif [ "$D" = "#" ]; then
echo -e "(staged) "
else
echo ""
fi
}
# Change the command line format and color
# \u User name
# \h Host name
# \w Directory
# $(parse_git_branch) Current git branch name
export PS1=':\[\e[1;33m\]\W\[\e[0;33m\]$(parse_git_branch)\[\e[0,36m\]$(parse_git_dirty)\[\e[1;33m\]$ \[\e[0m\]'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment