svn-fast-info.plugin.zsh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. function svn_prompt_info() {
  2. local info
  3. info=$(LANG= svn info 2>&1) || return 1 # capture stdout and stderr
  4. local repo_need_upgrade=$(svn_repo_need_upgrade $info)
  5. if [[ -n $repo_need_upgrade ]]; then
  6. printf '%s%s%s%s%s%s%s\n' \
  7. "$ZSH_PROMPT_BASE_COLOR" \
  8. "$ZSH_THEME_SVN_PROMPT_PREFIX" \
  9. "$ZSH_PROMPT_BASE_COLOR" \
  10. "$repo_need_upgrade" \
  11. "$ZSH_PROMPT_BASE_COLOR" \
  12. "$ZSH_THEME_SVN_PROMPT_SUFFIX" \
  13. "$ZSH_PROMPT_BASE_COLOR"
  14. else
  15. printf '%s%s%s%s %s%s%s:%s%s%s%s' \
  16. "$ZSH_PROMPT_BASE_COLOR" \
  17. "$ZSH_THEME_SVN_PROMPT_PREFIX" \
  18. "$(svn_status_info $info)" \
  19. "$ZSH_PROMPT_BASE_COLOR" \
  20. \
  21. "$ZSH_THEME_BRANCH_NAME_COLOR" \
  22. "${$(svn_current_branch_name $info):gs/%/%%}" \
  23. "$ZSH_PROMPT_BASE_COLOR" \
  24. \
  25. "$(svn_current_revision $info)" \
  26. "$ZSH_PROMPT_BASE_COLOR" \
  27. "$ZSH_THEME_SVN_PROMPT_SUFFIX" \
  28. "$ZSH_PROMPT_BASE_COLOR"
  29. fi
  30. }
  31. function svn_repo_need_upgrade() {
  32. command grep -q "E155036" <<< "${1:-$(LANG= svn info 2>/dev/null)}" && \
  33. echo "E155036: upgrade repo with svn upgrade"
  34. }
  35. function svn_current_branch_name() {
  36. omz_urldecode "$(
  37. command grep '^URL:' <<< "${1:-$(svn info 2>/dev/null)}" | command grep -Eo '(tags|branches)/[^/]+|trunk'
  38. )"
  39. }
  40. function svn_repo_root_name() {
  41. command grep '^Repository\ Root:' <<< "${1:-$(LANG= svn info 2>/dev/null)}" | sed 's#.*/##'
  42. }
  43. function svn_current_revision() {
  44. echo "${1:-$(LANG= svn info 2>/dev/null)}" | sed -n 's/Revision: //p'
  45. }
  46. function svn_status_info() {
  47. local svn_status_string="$ZSH_THEME_SVN_PROMPT_CLEAN"
  48. local svn_status="$(svn status 2>/dev/null)";
  49. if command grep -E '^\s*A' &>/dev/null <<< "$svn_status"; then
  50. svn_status_string+="${ZSH_THEME_SVN_PROMPT_ADDITIONS:-+}"
  51. fi
  52. if command grep -E '^\s*D' &>/dev/null <<< "$svn_status"; then
  53. svn_status_string+="${ZSH_THEME_SVN_PROMPT_DELETIONS:-✖}"
  54. fi
  55. if command grep -E '^\s*M' &>/dev/null <<< "$svn_status"; then
  56. svn_status_string+="${ZSH_THEME_SVN_PROMPT_MODIFICATIONS:-✎}"
  57. fi
  58. if command grep -E '^\s*[R~]' &>/dev/null <<< "$svn_status"; then
  59. svn_status_string+="${ZSH_THEME_SVN_PROMPT_REPLACEMENTS:-∿}"
  60. fi
  61. if command grep -E '^\s*\?' &>/dev/null <<< "$svn_status"; then
  62. svn_status_string+="${ZSH_THEME_SVN_PROMPT_UNTRACKED:-?}"
  63. fi
  64. if command grep -E '^\s*[CI!L]' &>/dev/null <<< "$svn_status"; then
  65. svn_status_string+="${ZSH_THEME_SVN_PROMPT_DIRTY:-!}"
  66. fi
  67. echo $svn_status_string
  68. }