zshrc: Move preexec() code to hooks
authorFrank Terbeck <ft@grml.org>
Tue, 5 Mar 2013 14:22:03 +0000 (15:22 +0100)
committerFrank Terbeck <ft@grml.org>
Tue, 5 Mar 2013 17:22:01 +0000 (18:22 +0100)
This allows for way more control and customisation by the user, just
like the same move with precmd(), that was done earlier does.

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

index 7d23055..94420c7 100644 (file)
@@ -1671,29 +1671,23 @@ function grml_vcs_to_screen_title () {
     fi
 }
 
-zrcautoload add-zsh-hook || add-zsh-hook () { :; }
-if [[ $NOPRECMD -gt 0 ]]; then
-    add-zsh-hook precmd grml_reset_screen_title
-    add-zsh-hook precmd grml_vcs_to_screen_title
-fi
-
-# preexec() => a function running before every command
-is4 && [[ $NOPRECMD -eq 0 ]] && \
-preexec () {
-    [[ $NOPRECMD -gt 0 ]] && return 0
-# set hostname if not running on host with name 'grml'
+function grml_maintain_name () {
+    # set hostname if not running on host with name 'grml'
     if [[ -n "$HOSTNAME" ]] && [[ "$HOSTNAME" != $(hostname) ]] ; then
        NAME="@$HOSTNAME"
     fi
-# get the name of the program currently running and hostname of local machine
-# set screen window title if running in a screen
+}
+
+function grml_cmd_to_screen_title () {
+    # get the name of the program currently running and hostname of local
+    # machine set screen window title if running in a screen
     if [[ "$TERM" == screen* ]] ; then
-        # local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}       # don't use hostname
-        local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME" # use hostname
+        local CMD="${1[(wr)^(*=*|sudo|ssh|-*)]}$NAME"
         ESC_print ${CMD}
     fi
-# adjust title of xterm
-    [[ ${NOTITLE} -gt 0 ]] && return 0
+}
+
+function grml_control_xterm_title () {
     case $TERM in
         (xterm*|rxvt*)
             set_title "${(%):-"%n@%m:"}" "$1"
@@ -1701,6 +1695,17 @@ preexec () {
     esac
 }
 
+zrcautoload add-zsh-hook || add-zsh-hook () { :; }
+if [[ $NOPRECMD -gt 0 ]]; then
+    add-zsh-hook precmd grml_reset_screen_title
+    add-zsh-hook precmd grml_vcs_to_screen_title
+    add-zsh-hook preexec grml_maintain_name
+    add-zsh-hook preexec grml_cmd_to_screen_title
+    if [[ $NOTITLE -eq 0 ]]; then
+        add-zsh-hook preexec grml_control_xterm_title
+    fi
+fi
+
 # 'hash' some often used directories
 #d# start
 hash -d deb=/var/cache/apt/archives