1b768a3b407103cd77d21d856051183960e0349e

Author
Brian Hartvigsen <brian.andrew@brianandjenny.com>
Committer
Brian Hartvigsen <brian.andrew@brianandjenny.com>
Date

Message

Update plugins/svn/svn.plugin.zsh

Behave more like lib/git.zsh.
Set `SVN_SHOW_BRANCH="true"` to display branch/tag or trunk instead of just repo name.
Falls back to repo name if branch information is not available.

Idea and awk call from revans/bash-it/themes/base.theme.bash

Diff

 1diff --git a/plugins/svn/svn.plugin.zsh b/plugins/svn/svn.plugin.zsh
 2index 4d5bfb8dd73193c3da8e70ae5cb1119312c4533a..bb46a7d0dad669c6760f1d736dd9c111dad53587 100644
 3--- a/plugins/svn/svn.plugin.zsh
 4+++ b/plugins/svn/svn.plugin.zsh
 5@@ -1,7 +1,14 @@
 6 function svn_prompt_info {
 7     if [ $(in_svn) ]; then
 8+        if [ "x$SVN_SHOW_BRANCH" = "xtrue" ]; then
 9+            unset SVN_SHOW_BRANCH
10+            _DISPLAY=$(svn_get_branch_name)
11+        else
12+            _DISPLAY=$(svn_get_repo_name)
13+        fi
14         echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_PREFIX\
15-$ZSH_THEME_REPO_NAME_COLOR$(svn_get_repo_name)$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_SUFFIX$ZSH_PROMPT_BASE_COLOR$(svn_dirty)$ZSH_PROMPT_BASE_COLOR"
16+$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"
17+        unset _DISPLAY
18     fi
19 }
20 
21@@ -20,6 +27,16 @@ function svn_get_repo_name {
22     fi
23 }
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+
35 function svn_get_rev_nr {
36     if [ $(in_svn) ]; then
37         svn info 2> /dev/null | sed -n s/Revision:\ //p