zshrc: New prompt: Provide fallback in case promptinit fails
authorFrank Terbeck <ft@grml.org>
Tue, 5 Mar 2013 13:35:46 +0000 (14:35 +0100)
committerFrank Terbeck <ft@grml.org>
Tue, 5 Mar 2013 17:22:01 +0000 (18:22 +0100)
This should not happen usually. But better be safe than sorry.

In case something goes wrong we only support _one_ prompt, with the original
root-is-red changeroo.  This is good enough as a fallback.

Signed-off-by: Frank Terbeck <ft@grml.org>
etc/zsh/zshrc

index b4ec1b7..7e2e53a 100644 (file)
@@ -1562,9 +1562,21 @@ if zrcautoload promptinit && promptinit 2>/dev/null ; then
     fi
 else
     print 'Notice: no promptinit available :('
-fi
 
-setopt prompt_subst
+    # Support a fallback, in case promptsys isn't available.
+    setopt prompt_subst
+
+    precmd() { (( ${+functions[vcs_info]} )) && vcs_info; }
+
+    p0="${RED}${EXITCODE}${WHITE}${debian_chroot:+($debian_chroot)}"
+    p1="${BLUE}%n${NO_COLOR}@%m %40<...<%B%~%b%<< "'${vcs_info_msg_0_}'"%# "
+    if (( EUID == 0 )); then
+        PROMPT="${BLUE}${p0}${RED}${p1}"
+    else
+        PROMPT="${RED}${p0}${BLUE}${p1}"
+    fi
+    unset p0 p1
+fi
 
 # make sure to use right prompt only when not running a command
 is41 && setopt transient_rprompt