update_current_git_vars (824B)
1 unset __CURRENT_GIT_BRANCH 2 unset __CURRENT_GIT_BRANCH_STATUS 3 unset __CURRENT_GIT_BRANCH_IS_DIRTY 4 5 local st="$(git status 2>/dev/null)" 6 local st2="$(git log -1 --pretty=%h 2>/dev/null)" 7 8 if [[ -n "$st" ]]; then 9 local -a arr 10 arr=(${(f)st}) 11 12 if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then 13 __CURRENT_GIT_BRANCH="$st2" 14 else 15 __CURRENT_GIT_BRANCH="${arr[1][(w)4]}"; 16 fi 17 18 if [[ $arr[2] =~ 'Your branch is' ]]; then 19 if [[ $arr[2] =~ 'ahead' ]]; then 20 __CURRENT_GIT_BRANCH_STATUS='ahead' 21 elif [[ $arr[2] =~ 'diverged' ]]; then 22 __CURRENT_GIT_BRANCH_STATUS='diverged' 23 else 24 __CURRENT_GIT_BRANCH_STATUS='behind' 25 fi 26 fi 27 28 if [[ ! $st =~ 'nothing to commit' ]]; then 29 __CURRENT_GIT_BRANCH_IS_DIRTY='1' 30 fi 31 fi