svn.plugin.zsh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. svn_prompt_info() {
  2. local _DISPLAY
  3. if in_svn; then
  4. if [[ "$SVN_SHOW_BRANCH" = true ]]; then
  5. unset SVN_SHOW_BRANCH
  6. _DISPLAY=$(svn_get_branch_name)
  7. else
  8. _DISPLAY=$(svn_get_repo_name)
  9. _DISPLAY=$(omz_urldecode "${_DISPLAY}")
  10. fi
  11. echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_PREFIX\
  12. $ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR$(svn_dirty)$(svn_dirty_pwd)$ZSH_PROMPT_BASE_COLOR"
  13. fi
  14. }
  15. in_svn() {
  16. svn info >/dev/null 2>&1
  17. }
  18. svn_get_repo_name() {
  19. if in_svn; then
  20. LANG=C svn info | sed -n 's/^Repository\ Root:\ .*\///p' | read SVN_ROOT
  21. LANG=C svn info | sed -n "s/^URL:\ .*$SVN_ROOT\///p"
  22. fi
  23. }
  24. svn_get_branch_name() {
  25. local _DISPLAY=$(
  26. LANG=C svn info 2> /dev/null | \
  27. awk -F/ \
  28. '/^URL:/ { \
  29. for (i=0; i<=NF; i++) { \
  30. if ($i == "branches" || $i == "tags" ) { \
  31. print $(i+1); \
  32. break;\
  33. }; \
  34. if ($i == "trunk") { print $i; break; } \
  35. } \
  36. }'
  37. )
  38. if [[ -z "$_DISPLAY" ]]; then
  39. svn_get_repo_name
  40. else
  41. echo $_DISPLAY
  42. fi
  43. }
  44. svn_get_rev_nr() {
  45. if in_svn; then
  46. LANG=C svn info 2> /dev/null | sed -n 's/Revision:\ //p'
  47. fi
  48. }
  49. svn_dirty() {
  50. svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
  51. }
  52. svn_dirty_choose() {
  53. if in_svn; then
  54. local root=$(LANG=C svn info 2> /dev/null | sed -n 's/^Working Copy Root Path: //p')
  55. if svn status $root 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
  56. # Grep exits with 0 when "One or more lines were selected", return "dirty".
  57. echo $1
  58. else
  59. # Otherwise, no lines were found, or an error occurred. Return clean.
  60. echo $2
  61. fi
  62. fi
  63. }
  64. svn_dirty_pwd () {
  65. svn_dirty_choose_pwd $ZSH_THEME_SVN_PROMPT_DIRTY_PWD $ZSH_THEME_SVN_PROMPT_CLEAN_PWD
  66. }
  67. svn_dirty_choose_pwd () {
  68. if in_svn; then
  69. if svn status "$PWD" 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
  70. # Grep exits with 0 when "One or more lines were selected", return "dirty".
  71. echo $1
  72. else
  73. # Otherwise, no lines were found, or an error occurred. Return clean.
  74. echo $2
  75. fi
  76. fi
  77. }