diff --git a/README.md b/README.md index 02277b1..75fd4c0 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,25 @@ fork自 oh my zsh,更纯净 更快速 ~/.fzf/install ``` +## CONFIGURATION + +```plaintext +# 以下env如果需要请在source omz.zsh 前定义 + +_OMZ_APPLY_PREEXEC_HOOK + 是否允许OMZ开启"命令发生前"相关hook + 默认true + 行为: + 1. 执行命令前 将修改当前终端会话的title为: $cmd + +_OMZ_APPLY_CHPWD_HOOK + 是否允许OMZ开启"pwd变更后"相关hook + 默认true + 行为: + 1. 载入时,会自动切换到上一次cd过的目录 + 2. 发生cd命令时,自动记录当前cd的目录(在缓存文件中) +``` + ## PLUGINS 1. z.lua diff --git a/config/hook.zsh b/config/hook.zsh index 3c24d64..3b4a46c 100644 --- a/config/hook.zsh +++ b/config/hook.zsh @@ -1,9 +1,16 @@ # auto update the terminal name -preexec_hook() { _cmd=($(echo $2)); print -n "\e]2;${(q)_cmd[1]}\a"; } -add-zsh-hook -Uz preexec preexec_hook +_apply_preexec_hook() { + preexec_hook() { _cmd=($(echo $2)); print -n "\e]2;${(q)_cmd[1]}\a"; } + add-zsh-hook -Uz preexec preexec_hook +} # auto to last pwd -chpwd_hook() { echo $PWD > $OMZ/cache/currentdir } -add-zsh-hook -Uz chpwd chpwd_hook -currentdir=$(cat $OMZ/cache/currentdir 2>/dev/null) -[ -d "$currentdir" ] && cd $currentdir +_apply_chpwd_hook() { + chpwd_hook() { echo $PWD > $OMZ/cache/currentdir } + add-zsh-hook -Uz chpwd chpwd_hook + currentdir=$(cat $OMZ/cache/currentdir 2>/dev/null) + [ -d "$currentdir" ] && cd $currentdir +} + +[ "$_OMZ_APPLY_PREEXEC_HOOK" != "false" ] && _apply_preexec_hook +[ "$_OMZ_APPLY_CHPWD_HOOK" != "false" ] && _apply_chpwd_hook