zshrc: prefer external vcs_info if available, fall back to internal otherwise (thanks...
authorMichael Prokop <mika@grml.org>
Thu, 10 Jun 2010 14:09:40 +0000 (16:09 +0200)
committerMichael Prokop <mika@grml.org>
Thu, 10 Jun 2010 14:09:40 +0000 (16:09 +0200)
etc/zsh/zshrc

index 96064fb..7874e22 100644 (file)
@@ -1143,6 +1143,12 @@ if ! is41 ; then
     zstyle ':vcs_info:*' enable false
 fi
 
+if zrcautoload vcs_info; then
+    GRML_VCS_INFO=0
+else
+# I'm not reindenting the whole code below.
+GRML_VCS_INFO=1
+
 # The following code is imported from the file 'zsh/functions/vcs_info'
 # from <http://ft.bewatermyfriend.org/comp/zsh/zsh-dotfiles.tar.bz2>,
 # which distributed under the same terms as zsh itself.
@@ -1971,6 +1977,8 @@ vcs_info () { # {{{
 VCS_INFO_set --nvcs preinit
 # }}}
 
+fi
+
 # 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_.
@@ -2045,6 +2053,8 @@ is4 && [[ $NOPRECMD -eq 0 ]] && precmd () {
     if [[ $TERM == screen* ]] ; then
         if [[ -n ${VCS_INFO_message_1_} ]] ; then
             ESC_print ${VCS_INFO_message_1_}
+        elif [[ -n ${vcs_info_msg_1_} ]] ; then
+            ESC_print ${vcs_info_msg_1_}
         else
             ESC_print "zsh"
         fi
@@ -2105,23 +2115,29 @@ fi
 
 # don't use colors on dumb terminals (like emacs):
 if [[ "$TERM" == dumb ]] ; then
-    PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+    PROMPT="${EXITCODE}${debian_chroot:+($debian_chroot)}%n@%m %40<...<%B%~%b%<< "
 else
     # only if $GRMLPROMPT is set (e.g. via 'GRMLPROMPT=1 zsh') use the extended prompt
     # set variable identifying the chroot you work in (used in the prompt below)
     if [[ $GRMLPROMPT -gt 0 ]] ; then
         PROMPT="${RED}${EXITCODE}${CYAN}[%j running job(s)] ${GREEN}{history#%!} ${RED}%(3L.+.) ${BLUE}%* %D
-${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
     else
         # This assembles the primary prompt string
         if (( EUID != 0 )); then
-            PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+            PROMPT="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${BLUE}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
         else
-            PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "'${VCS_INFO_message_0_}'"%# "
+            PROMPT="${BLUE}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}${RED}%n${NO_COLOUR}@%m %40<...<%B%~%b%<< "
         fi
     fi
 fi
 
+if (( GRML_VCS_INFO )); then
+    PROMPT="${PROMPT}"'${VCS_INFO_message_0_}'"%# "
+else
+    PROMPT="${PROMPT}"'${vcs_info_msg_0_}'"%# "
+fi
+
 # if we are inside a grml-chroot set a specific prompt theme
 if [[ -n "$GRML_CHROOT" ]] ; then
     PROMPT="%{$fg[red]%}(CHROOT) %{$fg_bold[red]%}%n%{$fg_no_bold[white]%}@%m %40<...<%B%~%b%<< %\# "