zshrc: Move CNF handler to a better place
[grml-etc-core.git] / etc / zsh / zshrc
index 5c9af65..7d23055 100644 (file)
@@ -144,6 +144,12 @@ is433(){
     return 1
 }
 
+is437(){
+    [[ $ZSH_VERSION == 4.3.<7->* || $ZSH_VERSION == 4.<4->* \
+                                 || $ZSH_VERSION == <5->* ]] && return 0
+    return 1
+}
+
 is439(){
     [[ $ZSH_VERSION == 4.3.<9->* || $ZSH_VERSION == 4.<4->* \
                                  || $ZSH_VERSION == <5->* ]] && return 0
@@ -979,6 +985,17 @@ for rh in run-help{,-git,-svk,-svn}; do
     zrcautoload $rh
 done; unset rh
 
+# command not found handling
+
+(( ${COMMAND_NOT_FOUND} == 1 )) &&
+function command_not_found_handler() {
+    emulate -L zsh
+    if [[ -x ${GRML_ZSH_CNF_HANDLER} ]] ; then
+        ${GRML_ZSH_CNF_HANDLER} $1
+    fi
+    return 1
+}
+
 # completion system
 if zrcautoload compinit ; then
     compinit || print 'Notice: no compinit available :('
@@ -1234,8 +1251,6 @@ PS4='+%N:%i:%_> '
 #    - battery status
 #    - debian_chroot
 #    - vcs_info setup and version specific fixes
-#    - command-not-found handling
-#      (TODO: This has nothing to do with prompts: move!)
 
 # display battery status on right side of prompt via running 'BATTERY=1 zsh'
 if [[ $BATTERY -gt 0 ]] ; then
@@ -1261,7 +1276,7 @@ fi
 
 # set variable debian_chroot if running in a chroot with /etc/debian_chroot
 if [[ -z "$debian_chroot" ]] && [[ -r /etc/debian_chroot ]] ; then
-    debian_chroot=$(cat /etc/debian_chroot)
+    debian_chroot=$(</etc/debian_chroot)
 fi
 
 # gather version control information for inclusion in a prompt
@@ -1301,17 +1316,6 @@ else
     zstyle ':vcs_info:(sv[nk]|bzr):*' branchformat "%b${RED}:${YELLOW}%r"
 fi
 
-# command not found handling
-
-(( ${COMMAND_NOT_FOUND} == 1 )) &&
-function command_not_found_handler() {
-    emulate -L zsh
-    if [[ -x ${GRML_ZSH_CNF_HANDLER} ]] ; then
-        ${GRML_ZSH_CNF_HANDLER} $1
-    fi
-    return 1
-}
-
 # Now for the fun part: The grml prompt themes in `promptsys' mode of operation
 
 # This actually defines three prompts:
@@ -1567,6 +1571,22 @@ function prompt_grml_precmd_worker () {
     fi
 }
 
+grml_prompt_fallback() {
+    setopt prompt_subst
+    precmd() {
+        (( ${+functions[vcs_info]} )) && vcs_info
+    }
+
+    p0="${RED}%(?..%? )${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
+}
+
 if zrcautoload promptinit && promptinit 2>/dev/null ; then
     # Since we define the required functions in here and not in files in
     # $fpath, we need to stick the theme's name into `$prompt_themes'
@@ -1574,7 +1594,14 @@ if zrcautoload promptinit && promptinit 2>/dev/null ; then
     prompt_themes+=( grml grml-chroot grml-large )
     # Also, keep the array sorted...
     prompt_themes=( "${(@on)prompt_themes}" )
+else
+    print 'Notice: no promptinit available :('
+    grml_prompt_fallback
+fi
 
+if is437; then
+    # The prompt themes use modern features of zsh, that require at least
+    # version 4.3.7 of the shell. Use the fallback otherwise.
     if [[ $BATTERY -gt 0 ]]; then
         zstyle ':prompt:grml:right:setup' items sad-smiley battery
         add-zsh-hook precmd battery
@@ -1601,26 +1628,10 @@ if zrcautoload promptinit && promptinit 2>/dev/null ; then
         prompt grml
     fi
 else
-    print 'Notice: no promptinit available :('
-
-    # Support a fallback, in case promptsys isn't available.
-    setopt prompt_subst
-
-    precmd() { (( ${+functions[vcs_info]} )) && vcs_info; }
-
-    p0="${RED}%(?..%? )${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
+    grml_prompt_fallback
 fi
 
-# make sure to use right prompt only when not running a command
-is41 && setopt transient_rprompt
-
+# Terminal-title wizardry
 
 function ESC_print () {
     info_print $'\ek' $'\e\\' "$@"