9ce1b6289aebc8e19b8bb25e4f7ac1cbc84e83de

Author
Brice Dutheil <brice.dutheil@gmail.com>
Committer
Brice Dutheil <brice.dutheil@gmail.com>
Date

Message

new faster SVN plugin

Diff

 1diff --git a/plugins/svn-fast-info/svn-fast-info.plugin.zsh b/plugins/svn-fast-info/svn-fast-info.plugin.zsh
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..d8fc539899285c2c67add06415d6e6356ce88cb1
 4--- /dev/null
 5+++ b/plugins/svn-fast-info/svn-fast-info.plugin.zsh
 6@@ -0,0 +1,64 @@
 7+# vim:ft=zsh ts=2 sw=2 sts=2
 8+#
 9+# Faster alternative to the current SVN plugin implementation.
10+#
11+# Works with svn 1.6, 1.7, 1.8.
12+# Use `svn_prompt_info` method to enquire the svn data.
13+# It's faster because his efficient use of svn (single svn call) done in the `parse_svn` function
14+# Also changed prompt suffix *after* the svn dirty marker
15+#
16+# *** IMPORTANT *** DO NO USE with the simple svn plugin, this plugin acts as a replacement of it.
17+
18+function parse_svn() {
19+    info=$(svn info 2> /dev/null) || return
20+    in_svn=true
21+	repo_need_upgrade="$(svn_repo_need_upgrade $info)"
22+    svn_branch_name="$(svn_get_branch_name $info)"
23+    svn_dirty="$(svn_dirty_choose)"
24+    svn_repo_name="$(svn_get_repo_name $info)"
25+    svn_rev="$(svn_get_revision $info)"
26+}
27+
28+function svn_prompt_info() {
29+    eval parse_svn
30+
31+    if [ ${in_svn} ]; then
32+        echo "$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_PREFIX\
33+$ZSH_THEME_REPO_NAME_COLOR${svn_branch_name}\
34+$ZSH_PROMPT_BASE_COLOR${svn_dirty}\
35+$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_SUFFIX\
36+$ZSH_PROMPT_BASE_COLOR"
37+    fi
38+}
39+
40+
41+function svn_repo_need_upgrade() {
42+	info=$1
43+	[ -z "${info}" ] && info=$(svn info 2> /dev/null)
44+	[ "${info}" = "E155036" ] && echo "upgrade repo with svn upgrade"
45+}
46+
47+function svn_get_branch_name() {
48+	info=$1
49+	[ -z "${info}" ] && info=$(svn info 2> /dev/null)
50+    echo $info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$' | read SVN_URL
51+    echo $SVN_URL
52+}
53+
54+function svn_get_repo_name() {
55+	info=$1
56+	[ -z "${info}" ] && info=$(svn info 2> /dev/null)
57+    echo $info | sed -n 's/Repository\ Root:\ .*\///p' | read SVN_ROOT
58+    echo $info | sed -n "s/URL:\ .*$SVN_ROOT\///p"
59+}
60+
61+function svn_get_revision() {
62+	info=$1
63+	[ -z "${info}" ] && info=$(svn info 2> /dev/null)
64+    echo $info 2> /dev/null | sed -n s/Revision:\ //p
65+}
66+
67+function svn_dirty_choose() {
68+    svn status | grep -E '^\s*[ACDIM!?L]' > /dev/null 2>/dev/null && echo $ZSH_THEME_SVN_PROMPT_DIRTY && return
69+    echo $ZSH_THEME_SVN_PROMPT_CLEAN
70+}