Guest User

Untitled

a guest
Dec 11th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function parse_git_branch {
  2. git rev-parse --git-dir &> /dev/null
  3. git_status="$(git status 2> /dev/null)"
  4. branch_pattern="^# On branch ([^${IFS}]*)"
  5. detached_branch_pattern="# Not currently on any branch"
  6. remote_pattern="# Your branch is (.*) of"
  7. diverge_pattern="# Your branch and (.*) have diverged"
  8. if [[ ${git_status}} =~ "Changed but not updated" ]]; then
  9. state="${RED}⚡"
  10. fi
  11. # add an else if or two here if you want to get more specific
  12. if [[ ${git_status} =~ ${remote_pattern} ]]; then
  13. if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
  14. remote="${YELLOW}↑"
  15. else
  16. remote="${YELLOW}↓"
  17. fi
  18. fi
  19. if [[ ${git_status} =~ ${diverge_pattern} ]]; then
  20. remote="${YELLOW}↕"
  21. fi
  22. if [[ ${git_status} =~ ${branch_pattern} ]]; then
  23. branch="${YELLOW}${BASH_REMATCH[1]}"
  24. elif [[ ${git_status} =~ ${detached_branch_pattern} ]]; then
  25. branch="${YELLOW}NO BRANCH"
  26. fi
  27.  
  28. if [[ ${#state} -gt "0" || ${#remote} -gt "0" ]]; then
  29. s=" "
  30. fi
  31.  
  32. echo " (${branch}${s}${remote}${state}${COLOR_NONE})"
  33. }
Add Comment
Please, Sign In to add comment