daily pastebin goal
59%
SHARE
TWEET

Untitled

a guest Nov 9th, 2018 72 in 358 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # get current branch in git repo
  2. function parse_git_branch() {
  3.     BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
  4.     if [ ! "${BRANCH}" == "" ]
  5.     then
  6.         STAT=`parse_git_dirty`
  7.         echo "[${BRANCH}${STAT}]"
  8.     else
  9.         echo ""
  10.     fi
  11. }
  12.  
  13. # get current status of git repo
  14. function parse_git_dirty {
  15.     status=`git status 2>&1 | tee`
  16.     dirty=`echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?"`
  17.     untracked=`echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?"`
  18.     ahead=`echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?"`
  19.     newfile=`echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?"`
  20.     renamed=`echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?"`
  21.     deleted=`echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?"`
  22.     bits=''
  23.     if [ "${renamed}" == "0" ]; then
  24.         bits=">${bits}"
  25.     fi
  26.     if [ "${ahead}" == "0" ]; then
  27.         bits="*${bits}"
  28.     fi
  29.     if [ "${newfile}" == "0" ]; then
  30.         bits="+${bits}"
  31.     fi
  32.     if [ "${untracked}" == "0" ]; then
  33.         bits="?${bits}"
  34.     fi
  35.     if [ "${deleted}" == "0" ]; then
  36.         bits="x${bits}"
  37.     fi
  38.     if [ "${dirty}" == "0" ]; then
  39.         bits="!${bits}"
  40.     fi
  41.     if [ ! "${bits}" == "" ]; then
  42.         echo " ${bits}"
  43.     else
  44.         echo ""
  45.     fi
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top