git.zsh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # get the name of the branch we are on
  2. function git_prompt_info() {
  3. ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  4. echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
  5. }
  6. parse_git_dirty () {
  7. if [[ -n $(git status -s 2> /dev/null) ]]; then
  8. echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
  9. else
  10. echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
  11. fi
  12. }
  13. # get the status of the working tree
  14. git_prompt_status() {
  15. INDEX=$(git status --porcelain 2> /dev/null)
  16. STATUS=""
  17. if $(echo "$INDEX" | grep '^?? ' &> /dev/null); then
  18. STATUS="$ZSH_THEME_GIT_PROMPT_UNTRACKED$STATUS"
  19. fi
  20. if $(echo "$INDEX" | grep '^A ' &> /dev/null); then
  21. STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
  22. elif $(echo "$INDEX" | grep '^M ' &> /dev/null); then
  23. STATUS="$ZSH_THEME_GIT_PROMPT_ADDED$STATUS"
  24. fi
  25. if $(echo "$INDEX" | grep '^ M ' &> /dev/null); then
  26. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  27. elif $(echo "$INDEX" | grep '^AM ' &> /dev/null); then
  28. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  29. elif $(echo "$INDEX" | grep '^ T ' &> /dev/null); then
  30. STATUS="$ZSH_THEME_GIT_PROMPT_MODIFIED$STATUS"
  31. fi
  32. if $(echo "$INDEX" | grep '^R ' &> /dev/null); then
  33. STATUS="$ZSH_THEME_GIT_PROMPT_RENAMED$STATUS"
  34. fi
  35. if $(echo "$INDEX" | grep '^ D ' &> /dev/null); then
  36. STATUS="$ZSH_THEME_GIT_PROMPT_DELETED$STATUS"
  37. fi
  38. if $(echo "$INDEX" | grep '^UU ' &> /dev/null); then
  39. STATUS="$ZSH_THEME_GIT_PROMPT_UNMERGED$STATUS"
  40. fi
  41. echo $STATUS
  42. }