svn-fast-info.plugin.zsh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. function svn_prompt_info() {
  2. local info
  3. info=$(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)" \
  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. grep -q "E155036" <<< "${1:-$(svn info 2> /dev/null)}" && \
  33. echo "E155036: upgrade repo with svn upgrade"
  34. }
  35. function svn_current_branch_name() {
  36. grep '^URL:' <<< "${1:-$(svn info 2> /dev/null)}" | egrep -o '(tags|branches)/[^/]+|trunk'
  37. }
  38. function svn_repo_root_name() {
  39. grep '^Repository\ Root:' <<< "${1:-$(svn info 2> /dev/null)}" | sed 's#.*/##'
  40. }
  41. function svn_current_revision() {
  42. echo "${1:-$(svn info 2> /dev/null)}" | sed -n 's/Revision: //p'
  43. }
  44. function svn_status_info() {
  45. local svn_status_string="$ZSH_THEME_SVN_PROMPT_CLEAN"
  46. local svn_status="$(svn status 2> /dev/null)";
  47. if command grep -E '^\s*A' &> /dev/null <<< $svn_status; then
  48. svn_status_string="$svn_status_string${ZSH_THEME_SVN_PROMPT_ADDITIONS:-+}"
  49. fi
  50. if command grep -E '^\s*D' &> /dev/null <<< $svn_status; then
  51. svn_status_string="$svn_status_string${ZSH_THEME_SVN_PROMPT_DELETIONS:-✖}"
  52. fi
  53. if command grep -E '^\s*M' &> /dev/null <<< $svn_status; then
  54. svn_status_string="$svn_status_string${ZSH_THEME_SVN_PROMPT_MODIFICATIONS:-✎}"
  55. fi
  56. if command grep -E '^\s*[R~]' &> /dev/null <<< $svn_status; then
  57. svn_status_string="$svn_status_string${ZSH_THEME_SVN_PROMPT_REPLACEMENTS:-∿}"
  58. fi
  59. if command grep -E '^\s*\?' &> /dev/null <<< $svn_status; then
  60. svn_status_string="$svn_status_string${ZSH_THEME_SVN_PROMPT_UNTRACKED:-?}"
  61. fi
  62. if command grep -E '^\s*[CI!L]' &> /dev/null <<< $svn_status; then
  63. svn_status_string="$svn_status_string${ZSH_THEME_SVN_PROMPT_DIRTY:-!}"
  64. fi
  65. echo $svn_status_string
  66. }