svn.plugin.zsh 1.7 KB

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