]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/svn-fast-info/svn-fast-info.plugin.zsh
46dd5cb0cf2c0feace9e437c393d1eadd9cfb67c
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / svn-fast-info / svn-fast-info.plugin.zsh
1 function svn_prompt_info() {
2   local info
3   info=$(LANG= svn info 2>&1) || return 1 # capture stdout and stderr
4   local repo_need_upgrade=$(svn_repo_need_upgrade $info)
5
6   if [[ -n $repo_need_upgrade ]]; then
7     printf '%s%s%s%s%s%s%s\n' \
8       "$ZSH_PROMPT_BASE_COLOR" \
9       "$ZSH_THEME_SVN_PROMPT_PREFIX" \
10       "$ZSH_PROMPT_BASE_COLOR" \
11       "$repo_need_upgrade" \
12       "$ZSH_PROMPT_BASE_COLOR" \
13       "$ZSH_THEME_SVN_PROMPT_SUFFIX" \
14       "$ZSH_PROMPT_BASE_COLOR"
15   else
16     printf '%s%s%s%s %s%s%s:%s%s%s%s' \
17       "$ZSH_PROMPT_BASE_COLOR" \
18       "$ZSH_THEME_SVN_PROMPT_PREFIX" \
19       "$(svn_status_info $info)" \
20       "$ZSH_PROMPT_BASE_COLOR" \
21       \
22       "$ZSH_THEME_BRANCH_NAME_COLOR" \
23       "${$(svn_current_branch_name $info):gs/%/%%}" \
24       "$ZSH_PROMPT_BASE_COLOR" \
25       \
26       "$(svn_current_revision $info)" \
27       "$ZSH_PROMPT_BASE_COLOR" \
28       "$ZSH_THEME_SVN_PROMPT_SUFFIX" \
29       "$ZSH_PROMPT_BASE_COLOR"
30   fi
31 }
32
33 function svn_repo_need_upgrade() {
34   command grep -q "E155036" <<< "${1:-$(LANG= svn info 2>/dev/null)}" && \
35     echo "E155036: upgrade repo with svn upgrade"
36 }
37
38 function svn_current_branch_name() {
39   omz_urldecode "$(
40     command grep '^URL:' <<< "${1:-$(svn info 2>/dev/null)}" | command grep -Eo '(tags|branches)/[^/]+|trunk'
41   )"
42 }
43
44 function svn_repo_root_name() {
45   command grep '^Repository\ Root:' <<< "${1:-$(LANG= svn info 2>/dev/null)}" | sed 's#.*/##'
46 }
47
48 function svn_current_revision() {
49   echo "${1:-$(LANG= svn info 2>/dev/null)}" | sed -n 's/Revision: //p'
50 }
51
52 function svn_status_info() {
53   local svn_status_string="$ZSH_THEME_SVN_PROMPT_CLEAN"
54   local svn_status="$(svn status 2>/dev/null)";
55   if command grep -E '^\s*A' &>/dev/null <<< "$svn_status"; then
56     svn_status_string+="${ZSH_THEME_SVN_PROMPT_ADDITIONS:-+}"
57   fi
58   if command grep -E '^\s*D' &>/dev/null <<< "$svn_status"; then
59     svn_status_string+="${ZSH_THEME_SVN_PROMPT_DELETIONS:-✖}"
60   fi
61   if command grep -E '^\s*M' &>/dev/null <<< "$svn_status"; then
62     svn_status_string+="${ZSH_THEME_SVN_PROMPT_MODIFICATIONS:-✎}"
63   fi
64   if command grep -E '^\s*[R~]' &>/dev/null <<< "$svn_status"; then
65     svn_status_string+="${ZSH_THEME_SVN_PROMPT_REPLACEMENTS:-∿}"
66   fi
67   if command grep -E '^\s*\?' &>/dev/null <<< "$svn_status"; then
68     svn_status_string+="${ZSH_THEME_SVN_PROMPT_UNTRACKED:-?}"
69   fi
70   if command grep -E '^\s*[CI!L]' &>/dev/null <<< "$svn_status"; then
71     svn_status_string+="${ZSH_THEME_SVN_PROMPT_DIRTY:-!}"
72   fi
73   echo $svn_status_string
74 }