Skip to content

Instantly share code, notes, and snippets.

@caspian311
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save caspian311/6c1d8d1ccf947e1e3c98 to your computer and use it in GitHub Desktop.

Select an option

Save caspian311/6c1d8d1ccf947e1e3c98 to your computer and use it in GitHub Desktop.
bash prompt with git status
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
WHITE="\[\033[1;37m\]"
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
foo=${ref#refs/heads/}
status=$(git status -s | awk '{print $1}' 2>&1)
echo "$status" | grep M > /dev/null 2>&1
changes=$?
echo "$status" | grep '??' > /dev/null 2>&1
newFiles=$?
echo "$status" | grep 'D' > /dev/null 2>&1
delFiles=$?
if [ $changes = 0 ]
then
foo="$foo*"
fi
if [ $newFiles = 0 ]
then
foo="$foo+"
fi
if [ $delFiles = 0 ]
then
foo="$foo-"
fi
echo "($foo)"
}
PS1="$WHITE[$GREEN\u@\h:\w$WHITE]$YELLOW\$(parse_git_branch)$GREEN\$ "
@caspian311
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment