From ba1f064357313201895505f658a18739dbb81be0 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Sat, 18 Jul 2015 17:27:18 +0200 Subject: [PATCH] Close #147 PR: Preserve preprompt on Ctrl+L. Fixes #145 --- pure.zsh | 17 +++++++++++++++++ readme.md | 6 ++++++ 2 files changed, 23 insertions(+) diff --git a/pure.zsh b/pure.zsh index 37c3bda..45840aa 100644 --- a/pure.zsh +++ b/pure.zsh @@ -47,6 +47,15 @@ prompt_pure_check_cmd_exec_time() { (($elapsed > ${PURE_CMD_MAX_EXEC_TIME:=5})) && prompt_pure_human_time $elapsed } +prompt_pure_clear_screen() { + # enable output to terminal + zle -I + # clear screen and move cursor to (0, 0) + print -n '\e[2J\e[0;0H' + # print preprompt + prompt_pure_preprompt_render precmd +} + prompt_pure_check_git_arrows() { # check if there is an upstream configured for this branch command git rev-parse --abbrev-ref @'{u}' &>/dev/null || return @@ -249,6 +258,7 @@ prompt_pure_setup() { prompt_opts=(subst percent) zmodload zsh/datetime + zmodload zsh/zle autoload -Uz add-zsh-hook autoload -Uz vcs_info autoload -Uz async && async @@ -261,6 +271,13 @@ prompt_pure_setup() { zstyle ':vcs_info:git*' formats ' %b' zstyle ':vcs_info:git*' actionformats ' %b|%a' + # if the user has not registered a custom zle widget for clear-screen, + # override the builtin one so that the preprompt is displayed correctly when + # ^L is issued. + if [[ $widgets[clear-screen] == 'builtin' ]]; then + zle -N clear-screen prompt_pure_clear_screen + fi + # show username@host if logged in through SSH [[ "$SSH_CONNECTION" != '' ]] && prompt_pure_username=' %F{242}%n@%m%f' diff --git a/readme.md b/readme.md index d6aeb00..a56205e 100644 --- a/readme.md +++ b/readme.md @@ -153,6 +153,12 @@ antigen bundle sindresorhus/pure ## FAQ +### My preprompt is missing when I clear the screen with Ctrl+L + +Pure doesn't register its custom *clear-screen* widget if it has been previously modified. If you haven't registered your own zle widget with `zle -N clear-screen custom-clear-screen` it might have been done by third-party modules. For example `zsh-syntax-highlighting` and `zsh-history-substring-search` are known to do this and they should for that reason be **the very last thing** in your `.zshrc` (as pointed out in their documentation). + +To find out the culprit that is overriding your *clear-screen* widget, you can run the following command: `zle -l | grep clear-screen`. + ### I am stuck in a shell loop in my terminal that ask me to authenticate. What should I do ? [This is a known issue](https://github.com/sindresorhus/pure/issues/76).