From 6a512b0c54fdc39142b1015386992387d68aab86 Mon Sep 17 00:00:00 2001 From: Frank Terbeck Date: Tue, 5 Mar 2013 15:22:03 +0100 Subject: [PATCH] zshrc: Move preexec() code to hooks 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 --- etc/zsh/zshrc | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 7d23055..94420c7 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -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 -- 2.1.4