Skip to content

Instantly share code, notes, and snippets.

@jFransham
Last active October 27, 2015 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jFransham/663bf009920d3f57f91d to your computer and use it in GitHub Desktop.
Save jFransham/663bf009920d3f57f91d to your computer and use it in GitHub Desktop.
#!/bin/bash
__git_ps1() {
if [ "$(git status -s 2>&1 1>/dev/null)" ]; then
return
fi
if [ -z "$(ps | grep fetch | grep -v grep)" ]; then
(git fetch 2>/dev/null 1>/dev/null &) > /dev/null
fi
local nn=$(git status -s 2>/dev/null | grep "??" | sed -n '$=')
local nc=$(git status -s 2>/dev/null | grep M | sed -n '$=')
local branch=$(git branch 2>/dev/null | grep "*" | sed 's/^* //')
nn=$nn
nc=$nc
local msg=""
local color=""
local uncolor=`echo -e "\001\033[0m\002"`
if [ "$(git status 2>/dev/null | grep "our branch is behind 'origin/")" ]; then
color=`echo -e "\001\033[0;31m\002<<"`
elif [ "$(git status 2>/dev/null | grep "our branch and" | grep "have diverged")" ]; then
color=`echo -e "\001\033[1;34m\002<>"`
elif [ "$(git diff --name-only HEAD origin/$branch 2>/dev/null)" ]; then
color=`echo -e "\001\033[1;31m\002>>"`
else
color=`echo -e "\001\033[1;32m\002"`
fi
if [ $nc ]; then
msg=$msg"-"$nc"c"
fi
if [ $nn ]; then
if [ $msg ]; then
msg=$msg","$nn"n"
else
msg=$msg"-"$nn"n"
fi
fi
echo -e "($color$branch$uncolor$msg)"
}
export PS1='\w$(__git_ps1) \u\$ '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment