]> ruderich.org/simon Gitweb - config/dotfiles.git/commitdiff
zsh: Support VCS_Info in versions earlier than 4.3.9.
authorSimon Ruderich <simon@ruderich.org>
Tue, 21 Apr 2009 19:07:18 +0000 (21:07 +0200)
committerSimon Ruderich <simon@ruderich.org>
Tue, 21 Apr 2009 19:07:18 +0000 (21:07 +0200)
The VCS_Info files must be available in ~/.zsh/functions/vcs_info for this to
work. A symbolic link can be used.

zsh/rc

diff --git a/zsh/rc b/zsh/rc
index e8792d1b5c24d4fc1d1a26888b5266b94df2fd33..472e92dfe918226e41f05e06ceba32fb8a3b1d91 100644 (file)
--- a/zsh/rc
+++ b/zsh/rc
@@ -104,8 +104,18 @@ PROMPT="%{${fg[green]}%}%B%m%b%{${fg[default]}%}:\
 %(1j.%{${fg[yellow]}%}%j%{${fg[default]}%}.)%(2L.+.)%# \
 %(?..(%{${fg[red]}%}%B%?%b%{${fg[default]}%}%) )"
 
-# VCS_Info was added in 4.3.9.
-if [[ $ZSH_VERSION == (4.3.<9->|4.<4->*|<5->*) ]]; then
+# VCS_Info was added in 4.3.9 but it works in earlier versions too. So load it
+# if the necessary files are available in ~/.zsh/functions/vcs_info (often a
+# symbolic link to current checkout of Zsh's sources).
+if [[ $ZSH_VERSION == (4.3.<9->|4.<4->*|<5->*) ||
+      -d ~/.zsh/functions/vcs_info ]]; then
+    # Update fpath to allow loading the VCS_Info functions.
+    if [[ -d ~/.zsh/functions/vcs_info ]]; then
+       fpath=(~/.zsh/functions/vcs_info/
+              ~/.zsh/functions/vcs_info/Backends
+              $fpath)
+    fi
+
     # Allow substitutions and expansions in the prompt, necessary for
     # vcs_info.
     setopt promptsubst
@@ -130,7 +140,14 @@ if [[ $ZSH_VERSION == (4.3.<9->|4.<4->*|<5->*) ]]; then
     add-zsh-hook precmd prompt_precmd
 
     # Display the vcs information in the right prompt.
-    RPROMPT='${vcs_info_msg_0_}'
+    if [[ $ZSH_VERSION == (4.3.<9->|4.<4->*|<5->*) ]]; then
+        RPROMPT='${vcs_info_msg_0_}'
+    # There is a bug in Zsh below 4.3.9 which displays a wrong symbol when
+    # ${vcs_info_msg_0_} is empty. Provide a workaround for those versions,
+    # thanks to Frank Terbeck <ft@bewatermyfriend.org> for it.
+    else
+        RPROMPT='${vcs_info_msg_0_:- }'
+    fi
 fi
 
 # When screen or xterm is used set the name of the window to the currently