Fix yet another bug in the shipped version of vcs_info()
[grml-etc-core.git] / etc / zsh / zshrc
index 61e86e5..cb911c1 100644 (file)
@@ -1128,8 +1128,8 @@ fi
 # from <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>,
 # which distributed under the same terms as zsh itself.
 
-# we will only be using one variable, so let the code know now.
-zstyle ':vcs_info:*' max-exports 1
+# we will be using two variables, so let the code know now.
+zstyle ':vcs_info:*' max-exports 2
 
 # vcs_info() documentation:
 #{{{
@@ -1417,17 +1417,21 @@ VCS_INFO_formats () { # {{{
         (( ${#msgs} < 1 )) && msgs[1]=' (%s)-[%b]-'
     fi
 
-    (( ${#msgs} > maxexports )) && msgs[${maxexports},-1]=()
+    (( ${#msgs} > maxexports )) && msgs[$(( maxexports + 1 )),-1]=()
     for i in {1..${#msgs}} ; do
-        zformat -f msg ${msgs[$i]} a:${action} b:${branch} s:${vcs} r:${base:t} R:${base} S:"$(VCS_INFO_reposub ${base})"
+        zformat -f msg ${msgs[$i]}                      \
+                        a:${action}                     \
+                        b:${branch}                     \
+                        r:${base:t}                     \
+                        s:${vcs}                        \
+                        R:${base}                       \
+                        S:"$(VCS_INFO_reposub ${base})"
         msgs[$i]=${msg}
     done
     return 0
 }
 # }}}
 VCS_INFO_maxexports () { #{{{
-    local -ix maxexports
-
     zstyle -s ":vcs_info:${vcs}:${usercontext}" "max-exports" maxexports || maxexports=2
     if [[ ${maxexports} != <-> ]] || (( maxexports < 1 )); then
         printf 'vcs_info(): expecting numeric arg >= 1 for max-exports (got %s).\n' ${maxexports}
@@ -1859,6 +1863,7 @@ vcs_info () { # {{{
     local -i found
     local -a VCSs disabled dps
     local -x vcs usercontext
+    local -ix maxexports
     local -ax msgs
     local -Ax vcs_comm
 
@@ -1925,14 +1930,20 @@ vcs_info () { # {{{
 VCS_INFO_set --nvcs preinit
 # }}}
 
-# change vcs_info formats for the grml prompt
+# Change vcs_info formats for the grml prompt. The 2nd format sets up
+# $vcs_info_msg_1_ to contain "zsh: repo-name" used to set our screen title.
+# TODO: The included vcs_info() version still uses $VCS_INFO_message_N_.
+#       That needs to be the use of $VCS_INFO_message_N_ needs to be changed
+#       to $vcs_info_msg_N_ as soon as we use the included version.
 if [[ "$TERM" == dumb ]] ; then
-    zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] "
-    zstyle ':vcs_info:*' formats       "(%s%)-[%b] "
+    zstyle ':vcs_info:*' actionformats "(%s%)-[%b|%a] " "zsh: %r"
+    zstyle ':vcs_info:*' formats       "(%s%)-[%b] "    "zsh: %r"
 else
     # these are the same, just with a lot of colours:
-    zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOUR} "
-    zstyle ':vcs_info:*' formats       "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOUR}%} "
+    zstyle ':vcs_info:*' actionformats "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${YELLOW}|${RED}%a${MAGENTA}]${NO_COLOUR} " \
+                                       "zsh: %r"
+    zstyle ':vcs_info:*' formats       "${MAGENTA}(${NO_COLOUR}%s${MAGENTA})${YELLOW}-${MAGENTA}[${GREEN}%b${MAGENTA}]${NO_COLOUR}%} " \
+                                       "zsh: %r"
     zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YELLOW}%r"
 fi
 
@@ -1955,21 +1966,21 @@ is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
     # update VCS information
     vcs_info
 
-    # allow manual overwriting of RPROMPT
-    if [[ -n $RPROMPT ]] ; then
-        [[ $TERM == screen* ]] && print -nP "\ekzsh\e\\"
-        # return 0
+    if [[ $TERM == screen* ]] ; then
+        if [[ -n ${VCS_INFO_message_1_} ]] ; then
+            print -nP "\ek${VCS_INFO_message_1_}\e\\"
+        else
+            print -nP "\ekzsh\e\\"
+        fi
     fi
     # just use DONTSETRPROMPT=1 to be able to overwrite RPROMPT
     if [[ $DONTSETRPROMPT -eq 0 ]] ; then
         if [[ $BATTERY -gt 0 ]] ; then
-            # update BATTERY information
+            # update battery (dropped into $PERCENT) information
             battery
-            RPROMPT="%(?..:()% ${PERCENT}${SCREENTITLE}"
-            # RPROMPT="${PERCENT}${SCREENTITLE}"
+            RPROMPT="%(?..:() ${PERCENT}"
         else
-            RPROMPT="%(?..:()% ${SCREENTITLE}"
-            # RPROMPT="${SCREENTITLE}"
+            RPROMPT="%(?..:() "
         fi
     fi
     # adjust title of xterm
@@ -1996,12 +2007,6 @@ preexec () {
         local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
         echo -ne "\ek$CMD\e\\"
     fi
-# set the screen title to "zsh" when sitting at the command prompt:
-    if [[ "$TERM" == screen* ]] ; then
-        SCREENTITLE=$'%{\ekzsh\e\\%}'
-    else
-        SCREENTITLE=''
-    fi
 # adjust title of xterm
     case $TERM in
         (xterm*|rxvt)