daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest Dec 15th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. function branch_name(){
  4.   git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
  5. }
  6.  
  7. function added(){
  8.   c=$(git status -s 2>&1 | awk 'BEGIN{a=0}{if($1=="A")a+=1}END{print a}')
  9.   [ "$c" == "" ] && c=0
  10.   echo $c
  11. }
  12.  
  13. function topush(){
  14.   c=$(git status | grep 'Your branch is ahead' | sed 's/.*by \([0-9]*\) commit.*/\1/')
  15.   [ "$c" == "" ] && c=0
  16.   echo $c
  17. }
  18.  
  19. function modified(){
  20.   git status -s 2>&1 | awk 'BEGIN{a=0}{if($1=="M")a+=1}END{print a}'
  21. }
  22.  
  23. function untracked(){
  24.   git status -s 2>&1 | awk 'BEGIN{a=0}{if($1=="??")a+=1}END{print a}'
  25. }
  26.  
  27. function __git_ps1(){
  28.   printf "%s,%d/%d\n" $(branch_name) $(modified) $(untracked)  
  29. }
  30.  
  31. function __git_ps1(){
  32.   ylw='\033[33m'
  33.   cya='\033[36m'
  34.   red='\033[31m'
  35.   grn='\033[32m'
  36.   blk='\033[30m'
  37.   rst='\033[0m'
  38.  
  39.   if [ "$(branch_name)" != "" ]; then
  40.  
  41.     def=${cya}
  42.  
  43.     [ $(modified) -gt 0 ]  && mod="${red}+$(modified)"  || mod="${def}0"
  44.     [ $(untracked) -gt 0 ] && unt="${red}+$(untracked)" || unt="${def}0"
  45.     [ $(added) -gt 0 ]     && add="${grn}+$(added)"     || add="${def}0"
  46.     [ $(topush) -gt 0 ]    && psh="${grn}+$(topush)"    || psh="${def}0"
  47.  
  48.     printf " ${ylw}[$(branch_name):${mod}${ylw}:${unt}${ylw}:${add}${ylw}:${psh}${ylw}]\n"
  49.   else
  50.     printf ""
  51.   fi
  52. }
  53.  
  54. export PS1='\[\033[0;32m\]\u\[\033[0m\] \w$(__git_ps1)\[\033[0m\] \$ '
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