svn.plugin.zsh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # vim:ft=zsh ts=2 sw=2 sts=2
  2. #
  3. function svn_prompt_info() {
  4. if in_svn; then
  5. if [ "x$SVN_SHOW_BRANCH" = "xtrue" ]; then
  6. unset SVN_SHOW_BRANCH
  7. _DISPLAY=$(svn_get_branch_name)
  8. else
  9. _DISPLAY=$(svn_get_repo_name)
  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)$ZSH_PROMPT_BASE_COLOR"
  13. unset _DISPLAY
  14. fi
  15. }
  16. function in_svn() {
  17. if $(svn info >/dev/null 2>&1); then
  18. return 0
  19. fi
  20. return 1
  21. }
  22. function svn_get_repo_name() {
  23. if in_svn; then
  24. svn info | sed -n 's/Repository\ Root:\ .*\///p' | read SVN_ROOT
  25. svn info | sed -n "s/URL:\ .*$SVN_ROOT\///p"
  26. fi
  27. }
  28. function svn_get_branch_name() {
  29. _DISPLAY=$(
  30. svn info 2> /dev/null | \
  31. awk -F/ \
  32. '/^URL:/ { \
  33. for (i=0; i<=NF; i++) { \
  34. if ($i == "branches" || $i == "tags" ) { \
  35. print $(i+1); \
  36. break;\
  37. }; \
  38. if ($i == "trunk") { print $i; break; } \
  39. } \
  40. }'
  41. )
  42. if [ "x$_DISPLAY" = "x" ]; then
  43. svn_get_repo_name
  44. else
  45. echo $_DISPLAY
  46. fi
  47. unset _DISPLAY
  48. }
  49. function svn_get_rev_nr() {
  50. if in_svn; then
  51. svn info 2> /dev/null | sed -n 's/Revision:\ //p'
  52. fi
  53. }
  54. function svn_dirty_choose() {
  55. if in_svn; then
  56. root=`svn info 2> /dev/null | sed -n 's/^Working Copy Root Path: //p'`
  57. if $(svn status $root 2> /dev/null | grep -Eq '^\s*[ACDIM!?L]'); then
  58. # Grep exits with 0 when "One or more lines were selected", return "dirty".
  59. echo $1
  60. else
  61. # Otherwise, no lines were found, or an error occurred. Return clean.
  62. echo $2
  63. fi
  64. fi
  65. }
  66. function svn_dirty() {
  67. svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
  68. }