1ad2556ce37d3900f38f5905ded60168dbd36ab7
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/svn/README.md b/plugins/svn/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..1f7b70c865bc002564e7e31c3ae2769aebc2d9fe
4--- /dev/null
5+++ b/plugins/svn/README.md
6@@ -0,0 +1,67 @@
7+# `svn` plugin
8+
9+This plugin adds some utility functions to display additional information regarding your current
10+svn repository. See http://subversion.apache.org/ for the full svn documentation.
11+
12+To use it, add `svn` to your plugins array:
13+
14+```zsh
15+plugins=(... svn)
16+```
17+
18+## Functions
19+
20+| Command | Description |
21+|:----------------------|:--------------------------------------------|
22+| `svn_prompt_info` | Shows svn prompt in themes |
23+| `in_svn` | Checks if we're in an svn repository |
24+| `svn_get_repo_name` | Get repository name |
25+| `svn_get_branch_name` | Get branch name (see [caveats](#caveats)) |
26+| `svn_get_rev_nr` | Get revision number |
27+| `svn_dirty` | Checks if there are changes in the svn repo |
28+
29+## Caveats
30+
31+The plugin expects the first directory to be the current branch / tag / trunk. So it returns
32+the first path element if you don't use branches.
33+
34+## Usage on themes
35+
36+To use this in the `agnoster` theme follow these instructions:
37+
38+1. Enable the svn plugin
39+
40+2. Add the following lines to your `zshrc` file:
41+
42+ ```shell
43+ prompt_svn() {
44+ local rev branch
45+ if in_svn; then
46+ rev=$(svn_get_rev_nr)
47+ branch=$(svn_get_branch_name)
48+ if [[ $(svn_dirty_choose_pwd 1 0) -eq 1 ]]; then
49+ prompt_segment yellow black
50+ echo -n "$rev@$branch"
51+ echo -n "±"
52+ else
53+ prompt_segment green black
54+ echo -n "$rev@$branch"
55+ fi
56+ fi
57+ }
58+ ```
59+
60+3. Override the agnoster `build_prompt()` function:
61+
62+ ```zsh
63+ build_prompt() {
64+ RETVAL=$?
65+ prompt_status
66+ prompt_context
67+ prompt_dir
68+ prompt_git
69+ prompt_svn
70+ prompt_end
71+ }
72+ ```
73+
74diff --git a/plugins/svn/svn.plugin.zsh b/plugins/svn/svn.plugin.zsh
75index 816055afe956311ee22ca2b564bb7eb521b3a526..fbc9ee5387e40feaf74a7c6b319f9a062a3aace0 100644
76--- a/plugins/svn/svn.plugin.zsh
77+++ b/plugins/svn/svn.plugin.zsh
78@@ -1,9 +1,7 @@
79-# vim:ft=zsh ts=2 sw=2 sts=2
80-#
81-function svn_prompt_info() {
82+svn_prompt_info() {
83 local _DISPLAY
84 if in_svn; then
85- if [ "x$SVN_SHOW_BRANCH" = "xtrue" ]; then
86+ if [[ "$SVN_SHOW_BRANCH" = true ]]; then
87 unset SVN_SHOW_BRANCH
88 _DISPLAY=$(svn_get_branch_name)
89 else
90@@ -16,23 +14,20 @@ $ZSH_THEME_REPO_NAME_COLOR$_DISPLAY$ZSH_PROMPT_BASE_COLOR$ZSH_THEME_SVN_PROMPT_S
91 }
92
93
94-function in_svn() {
95- if $(svn info >/dev/null 2>&1); then
96- return 0
97- fi
98- return 1
99+in_svn() {
100+ svn info >/dev/null 2>&1
101 }
102
103-function svn_get_repo_name() {
104+svn_get_repo_name() {
105 if in_svn; then
106- svn info | sed -n 's/Repository\ Root:\ .*\///p' | read SVN_ROOT
107- svn info | sed -n "s/URL:\ .*$SVN_ROOT\///p"
108+ LANG=C svn info | sed -n 's/^Repository\ Root:\ .*\///p' | read SVN_ROOT
109+ LANG=C svn info | sed -n "s/^URL:\ .*$SVN_ROOT\///p"
110 fi
111 }
112
113-function svn_get_branch_name() {
114+svn_get_branch_name() {
115 local _DISPLAY=$(
116- svn info 2> /dev/null | \
117+ LANG=C svn info 2> /dev/null | \
118 awk -F/ \
119 '/^URL:/ { \
120 for (i=0; i<=NF; i++) { \
121@@ -44,24 +39,28 @@ function svn_get_branch_name() {
122 } \
123 }'
124 )
125-
126- if [ "x$_DISPLAY" = "x" ]; then
127+
128+ if [[ -z "$_DISPLAY" ]]; then
129 svn_get_repo_name
130 else
131 echo $_DISPLAY
132 fi
133 }
134
135-function svn_get_rev_nr() {
136+svn_get_rev_nr() {
137 if in_svn; then
138- svn info 2> /dev/null | sed -n 's/Revision:\ //p'
139+ LANG=C svn info 2> /dev/null | sed -n 's/Revision:\ //p'
140 fi
141 }
142
143-function svn_dirty_choose() {
144+svn_dirty() {
145+ svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
146+}
147+
148+svn_dirty_choose() {
149 if in_svn; then
150- local root=`svn info 2> /dev/null | sed -n 's/^Working Copy Root Path: //p'`
151- if $(svn status $root 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'); then
152+ local root=$(LANG=C svn info 2> /dev/null | sed -n 's/^Working Copy Root Path: //p')
153+ if svn status $root 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
154 # Grep exits with 0 when "One or more lines were selected", return "dirty".
155 echo $1
156 else
157@@ -71,14 +70,13 @@ function svn_dirty_choose() {
158 fi
159 }
160
161-function svn_dirty() {
162- svn_dirty_choose $ZSH_THEME_SVN_PROMPT_DIRTY $ZSH_THEME_SVN_PROMPT_CLEAN
163+svn_dirty_pwd () {
164+ svn_dirty_choose_pwd $ZSH_THEME_SVN_PROMPT_DIRTY_PWD $ZSH_THEME_SVN_PROMPT_CLEAN_PWD
165 }
166
167-function svn_dirty_choose_pwd () {
168+svn_dirty_choose_pwd () {
169 if in_svn; then
170- local root=$PWD
171- if $(svn status $root 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'); then
172+ if svn status "$PWD" 2> /dev/null | command grep -Eq '^\s*[ACDIM!?L]'; then
173 # Grep exits with 0 when "One or more lines were selected", return "dirty".
174 echo $1
175 else
176@@ -87,9 +85,3 @@ function svn_dirty_choose_pwd () {
177 fi