SHARE
TWEET

Untitled

a guest Jan 16th, 2018 192 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. show_branch_status() {
  2.         local ref branch
  3.         ref=$(git symbolic-ref --quiet HEAD 2> /dev/null)
  4.         case $? in
  5.                 0) ;;
  6.                 128) return ;;
  7.                 *) ref=$(git rev-parse --short HEAD 2> /dev/null) || return ;;
  8.         esac
  9.         branch=${ref#refs/heads/}
  10.         printf ' (%s%s)' "$branch" "$(show_branch_changed)"
  11. }
  12.  
  13. show_branch_changed() {
  14.         local git_status symbols k
  15.         git_status=$(LC_ALL=C command git status 2>&1)
  16.  
  17.         declare -A messages
  18.  
  19.         messages=(
  20.                 'renamed:'                '>'
  21.                 'Your branch is ahead of' '*'
  22.                 'new file:'               '+'
  23.                 'Untracked files'         '?'
  24.                 'deleted'                 'x'
  25.                 'modified:'               '!'
  26.         )
  27.  
  28.         for k in ${(@k)messages}
  29.         do
  30.                 case $git_status in
  31.                         *${k}*) symbols="${messages[$k]}${symbols}" ;;
  32.                 esac
  33.         done
  34.  
  35.         [[ -n $symbols ]] && printf ' %s' "$symbols"
  36. }
  37.  
  38. precmd() {
  39.         psvar[3]=$(show_branch_status)
  40. }
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