From e3f1f87fc33a2ed851bbabcfff35ad7e8e0c6771 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 27 Jul 2016 12:04:49 +0300 Subject: [PATCH] Compare expanded preprompt when rendering (#214) * Compare expanded preprompt when rendering The expanded content of the preprompt was not considered previously when checking if the content had changed. E.g. path changes were never detected. The typeset (definition) and assignment are performed on separate lines as it would cause issues otherwise. Fixes #213. --- pure.zsh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pure.zsh b/pure.zsh index d1de220..b0ecfbf 100644 --- a/pure.zsh +++ b/pure.zsh @@ -141,12 +141,15 @@ prompt_pure_preprompt_render() { # execution time preprompt+="%F{yellow}${prompt_pure_cmd_exec_time}%f" + # make sure prompt_pure_last_preprompt is a global array + typeset -g -a prompt_pure_last_preprompt + # if executing through precmd, do not perform fancy terminal editing if [[ "$1" == "precmd" ]]; then print -P "\n${preprompt}" else - # only redraw if preprompt has changed - [[ "${prompt_pure_last_preprompt}" != "${preprompt}" ]] || return + # only redraw if the expanded preprompt has changed + [[ "${prompt_pure_last_preprompt[2]}" != "${(S%%)preprompt}" ]] || return # calculate length of preprompt and store it locally in preprompt_length integer preprompt_length lines @@ -157,7 +160,7 @@ prompt_pure_preprompt_render() { # calculate previous preprompt lines to figure out how the new preprompt should behave integer last_preprompt_length last_lines - prompt_pure_string_length_to_var "${prompt_pure_last_preprompt}" "last_preprompt_length" + prompt_pure_string_length_to_var "${prompt_pure_last_preprompt[1]}" "last_preprompt_length" (( last_lines = ( last_preprompt_length - 1 ) / COLUMNS + 1 )) # clr_prev_preprompt erases visual artifacts from previous preprompt @@ -190,8 +193,8 @@ prompt_pure_preprompt_render() { zle && zle .reset-prompt fi - # store previous preprompt for comparison - prompt_pure_last_preprompt=$preprompt + # store both unexpanded and expanded preprompt for comparison + prompt_pure_last_preprompt=("$preprompt" "${(S%%)preprompt}") } prompt_pure_precmd() {