From 2cc4962be6a65ce3d34197084216318e404cc2a9 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 19 Mar 2017 12:46:30 +0800 Subject: zsh: Move precmd() and preexec() to hooks.zsh --- _zsh/30-prompt.zsh | 7 +------ _zsh/40-hooks.zsh | 39 ++++++++++++--------------------------- 2 files changed, 13 insertions(+), 33 deletions(-) diff --git a/_zsh/30-prompt.zsh b/_zsh/30-prompt.zsh index d1c70c2..bd821d1 100644 --- a/_zsh/30-prompt.zsh +++ b/_zsh/30-prompt.zsh @@ -32,11 +32,6 @@ function gitpwd() { function myprompt() { - case "$TERM" in - xterm*|rxvt*) - precmd() { [[ -t 1 ]] && print -Pn "\e]0;%m: %~\a" } - preexec() { [[ -t 1 ]] && print -n "\e]0;$HOST: ${(q)1//(#m)[$'\000-\037\177-']/${(q)MATCH}}\a" } - esac setopt PROMPT_SUBST nbsp=$'\u00A0' PROMPT='%B%F{green}%m%(?.. %F{red}%??)%(1j. %F{yellow}%j&.)%b%f $(gitpwd)%B%(!.%F{red}.%F{green})%#${SSH_CONNECTION:+%#}$nbsp%b%f' @@ -46,7 +41,7 @@ function myprompt() { } -# Setup prompts +# Set prompts myprompt diff --git a/_zsh/40-hooks.zsh b/_zsh/40-hooks.zsh index defee0b..da15a29 100644 --- a/_zsh/40-hooks.zsh +++ b/_zsh/40-hooks.zsh @@ -1,34 +1,19 @@ # # zsh/hooks.zsh # - -# Put the string "hostname::/full/directory/path" in the title bar: -function set_term_title { - echo -ne "\e]2;$PWD\a" -} - -# Put the parentdir/currentdir in the tab -function set_term_tab { - echo -ne "\e]1;$PWD:h:t/$PWD:t\a" -} - -function precmd { - set_term_title - set_term_tab -} - - -#function set_running_app { -# printf "\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a" -#} -# -#function preexec { -# set_running_app -#} +# Credit: http://chneukirchen.org/dotfiles/.zshrc # -#function postexec { -# set_running_app -#} + +case "$TERM" in +xterm*|rxvt*) + function precmd() { + [[ -t 1 ]] && print -Pn "\e]0;%m: %~\a" + } + function preexec() { + [[ -t 1 ]] && print -n "\e]0;$HOST: ${(q)1//(#m)[$'\000-\037\177-']/${(q)MATCH}}\a" + } + ;; +esac # vim: set ts=8 sw=4 tw=0 fenc=utf-8 ft=zsh: # -- cgit v1.2.2