zshrc: Fix for detecting bzr repos with vcs_info()
[grml-etc-core.git] / etc / zsh / zshrc
index 7a5f2f3..1c38fcd 100644 (file)
@@ -1010,6 +1010,29 @@ if [[ -n "$BATTERY" ]] ; then
 fi
 # }}}
 
+# set colors for use in prompts {{{
+if zrcautoload colors && colors 2>/dev/null ; then
+    BLUE="%{${fg[blue]}%}"
+    RED="%{${fg_bold[red]}%}"
+    GREEN="%{${fg[green]}%}"
+    CYAN="%{${fg[cyan]}%}"
+    MAGENTA="%{${fg[magenta]}%}"
+    YELLOW="%{${fg[yellow]}%}"
+    WHITE="%{${fg[white]}%}"
+    NO_COLOUR="%{${reset_color}%}"
+else
+    BLUE=$'%{\e[1;34m%}'
+    RED=$'%{\e[1;31m%}'
+    GREEN=$'%{\e[1;32m%}'
+    CYAN=$'%{\e[1;36m%}'
+    WHITE=$'%{\e[1;37m%}'
+    MAGENTA='%{\e[1;35m%}'
+    YELLOW='%{\e[1;33m%}'
+    NO_COLOUR=$'%{\e[0m%}'
+fi
+
+# }}}
+
 # gather version control information for inclusion in a prompt {{{
 
 # vcs_info() documentation: {{{
@@ -1229,10 +1252,23 @@ VCS_INFO_bzr_get_data () { # {{{
 # }}}
 # VCS_INFO_*_detect () {{{
 
+VCS_INFO_detect_by_dir() {
+    local tool=${1} dirname=${2}
+    local basedir="."
+
+    check_com -c ${tool} || return 1
+    while [[ ! -d ${basedir}/${dirname} ]]; do
+        basedir=${basedir}/..
+        [[ $(VCS_INFO_realpath ${basedir}) = "/" ]] && return 1
+    done
+
+    printf '%s' $(VCS_INFO_realpath ${basedir})
+    return 0
+}
+
 VCS_INFO_bzr_detect() {
-    check_com -c bzr || return 1
-    [[ -d ".bzr" ]] && return 0
-    return 1
+    VCS_INFO_detect_by_dir 'bzr' '.bzr'
+    return $?
 }
 
 VCS_INFO_git_detect() {
@@ -1241,16 +1277,8 @@ VCS_INFO_git_detect() {
 }
 
 VCS_INFO_hg_detect() {
-    local basedir="."
-
-    check_com -c hg || return 1
-    while [[ ! -d ${basedir}/.hg ]]; do
-        basedir=${basedir}/..
-        [[ $(VCS_INFO_realpath ${basedir}) = "/" ]] && return 1
-    done
-
-    printf '%s' $(VCS_INFO_realpath ${basedir})
-    return 0
+    VCS_INFO_detect_by_dir 'hg' '.hg'
+    return $?
 }
 
 VCS_INFO_svk_detect() {
@@ -1315,10 +1343,8 @@ if [[ "$TERM" == dumb ]] ; then
     zstyle ':vcs_info:*' promptformat       "(%s%)-[%b] "
 else
     # these are the same, just with a lot of colours:
-    zstyle ':vcs_info:*' promptactionformat \
-"%{${fg[magenta]}%}(%{${reset_color}%}%s%{${fg[magenta]}%})%{${fg[yellow]}%}-%{${fg[magenta]}%}[%{${fg[green]}%}%b%{${fg[yellow]}%}|%{${fg[red]}%}%a%{${fg[magenta]}%}]%{${reset_color}%} "
-    zstyle ':vcs_info:*' promptformat \
-"%{${fg[magenta]}%}(%{${reset_color}%}%s%{${fg[magenta]}%})%{${fg[yellow]}%}-%{${fg[magenta]}%}[%{${fg[green]}%}%b%{${fg[magenta]}%}]%{${reset_color}%} "
+    zstyle ':vcs_info:*' promptactionformat "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOUR} "
+    zstyle ':vcs_info:*' promptformat       "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOUR}%} "
 fi
 
 # }}}
@@ -1397,23 +1423,6 @@ preexec () {
     esac
 }
 
-# set colors
-if zrcautoload colors && colors 2>/dev/null ; then
-    BLUE="%{${fg[blue]}%}"
-    RED="%{${fg_bold[red]}%}"
-    GREEN="%{${fg[green]}%}"
-    CYAN="%{${fg[cyan]}%}"
-    WHITE="%{${fg[white]}%}"
-    NO_COLOUR="%{${reset_color}%}"
-else
-    BLUE=$'%{\e[1;34m%}'
-    RED=$'%{\e[1;31m%}'
-    GREEN=$'%{\e[1;32m%}'
-    CYAN=$'%{\e[1;36m%}'
-    WHITE=$'%{\e[1;37m%}'
-    NO_COLOUR=$'%{\e[0m%}'
-fi
-
 EXITCODE="%(?..%?%1v )"
 PS2='`%_> '       # secondary prompt, printed when the shell needs more information to complete a command.
 PS3='?# '         # selection prompt used within a select loop.