svn-fast-info.plugin.zsh 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # vim:ft=zsh ts=2 sw=2 sts=2 et
  2. #
  3. # Faster alternative to the current SVN plugin implementation.
  4. #
  5. # Works with svn 1.6, 1.7, 1.8.
  6. # Use `svn_prompt_info` method to enquire the svn data.
  7. # It's faster because his efficient use of svn (single svn call) done in the `parse_svn` function
  8. # Also changed prompt suffix *after* the svn dirty marker
  9. #
  10. # *** IMPORTANT *** DO NO USE with the simple svn plugin, this plugin acts as a replacement of it.
  11. function svn_prompt_info() {
  12. local info
  13. info=$(svn info 2>&1) || return 1; # capture stdout and stderr
  14. local repo_need_upgrade=$(svn_repo_need_upgrade $info)
  15. if [ -n $repo_need_upgrade ]; then
  16. printf '%s%s%s%s%s%s%s\n' \
  17. $ZSH_PROMPT_BASE_COLOR \
  18. $ZSH_THEME_SVN_PROMPT_PREFIX \
  19. $ZSH_PROMPT_BASE_COLOR \
  20. $repo_need_upgrade \
  21. $ZSH_PROMPT_BASE_COLOR \
  22. $ZSH_THEME_SVN_PROMPT_SUFFIX \
  23. $ZSH_PROMPT_BASE_COLOR \
  24. else
  25. # something left for you to fix -
  26. # repo name and rev aren't used here, did you forget them?
  27. # especially since you set a repo name color
  28. # if the prompt is alright this way, leave it as is and just
  29. # delete the comment. The functions itself could stay imo,
  30. # gives others the chance to use them.
  31. printf '%s%s%s%s%s%s%s%s%s\n' \
  32. $ZSH_PROMPT_BASE_COLOR \
  33. $ZSH_THEME_SVN_PROMPT_PREFIX \
  34. $ZSH_THEME_REPO_NAME_COLOR \
  35. $(svn_get_branch_name $info)
  36. ${svn_branch_name}\
  37. $ZSH_PROMPT_BASE_COLOR
  38. $(svn_dirty_choose $info)
  39. $ZSH_PROMPT_BASE_COLOR
  40. $ZSH_THEME_SVN_PROMPT_SUFFIX\
  41. $ZSH_PROMPT_BASE_COLOR
  42. fi
  43. }
  44. function svn_repo_need_upgrade() {
  45. grep -q "E155036" <<< ${1:-$(svn info 2> /dev/null)} && \
  46. echo "E155036: upgrade repo with svn upgrade"
  47. }
  48. function svn_get_branch_name() {
  49. echo ${1:-$(svn info 2> /dev/null)} |\
  50. grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' |\
  51. egrep -o '[^/]+$'
  52. }
  53. function svn_get_repo_name() {
  54. # I think this can be further cleaned up as well, not sure how,
  55. # as I can't test it
  56. local svn_root
  57. local info=${1:-$(svn info 2> /dev/null)}
  58. echo $info | sed 's/Repository\ Root:\ .*\///p' | read svn_root
  59. echo $info | sed "s/URL:\ .*$svn_root\///p"
  60. }
  61. function svn_get_revision() {
  62. # does this work as it should?
  63. echo ${1:-$(svn info 2> /dev/null)} | sed 's/Revision: //p'
  64. }
  65. function svn_dirty_choose() {
  66. if svn status | grep -E '^\s*[ACDIM!?L]' &> /dev/null; then
  67. echo $ZSH_THEME_SVN_PROMPT_DIRTY
  68. else
  69. echo $ZSH_THEME_SVN_PROMPT_CLEAN
  70. fi
  71. }