From fe6f11960c9a69e50562f8b656819cb467f0dcc2 Mon Sep 17 00:00:00 2001 From: Zhiming Wang Date: Fri, 12 Jun 2015 17:33:51 -0700 Subject: [PATCH] rename two internal variables for readability * `prompt_pure_git_delay_dirty_check` holds the (finish) timestamp of the last dirty check (if the dirty check took more than 2 seconds); renamed to `prompt_pure_git_last_dirty_check_timestamp`. * Local variable `dirty_check` holds the elapsed time in seconds since the last dirty check (if the timestamp is set); renamed to `time_since_last_dirty_check`. --- pure.zsh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pure.zsh b/pure.zsh index f6fd34d..7b0db7e 100644 --- a/pure.zsh +++ b/pure.zsh @@ -83,7 +83,7 @@ prompt_pure_preprompt_render() { # set color for git branch/dirty status, change color if dirty checking has been delayed local git_color=242 - [[ -n ${prompt_pure_git_delay_dirty_check+x} ]] && git_color=red + [[ -n ${prompt_pure_git_last_dirty_check_timestamp+x} ]] && git_color=red # construct prompt, beginning with path local prompt="%F{blue}%~%f" @@ -192,7 +192,7 @@ prompt_pure_async_tasks() { # reset git preprompt variables, switching working tree unset prompt_pure_git_dirty - unset prompt_pure_git_delay_dirty_check + unset prompt_pure_git_last_dirty_check_timestamp # set the new working tree, prefixed with "x" prompt_pure_current_working_tree="x${working_tree}" @@ -209,9 +209,9 @@ prompt_pure_async_tasks() { fi # if dirty checking is sufficiently fast, tell worker to check it again, or wait for timeout - local dirty_check=$(( $EPOCHSECONDS - ${prompt_pure_git_delay_dirty_check:-0} )) - if (( $dirty_check > ${PURE_GIT_DELAY_DIRTY_CHECK:-1800} )); then - unset prompt_pure_git_delay_dirty_check + local time_since_last_dirty_check=$(( $EPOCHSECONDS - ${prompt_pure_git_last_dirty_check_timestamp:-0} )) + if (( $time_since_last_dirty_check > ${PURE_GIT_DELAY_DIRTY_CHECK:-1800} )); then + unset prompt_pure_git_last_dirty_check_timestamp # check check if there is anything to pull async_job "prompt_pure" prompt_pure_async_git_dirty "${PURE_GIT_UNTRACKED_DIRTY:-1}" "$working_tree" fi @@ -227,9 +227,10 @@ prompt_pure_async_callback() { prompt_pure_git_dirty=$output prompt_pure_preprompt_render - # when prompt_pure_git_delay_dirty_check is set, the git info is displayed in a different color, this is why the - # prompt is rendered before the variable is (potentially) set - (( $exec_time > 2 )) && prompt_pure_git_delay_dirty_check=$EPOCHSECONDS + # When prompt_pure_git_last_dirty_check_timestamp is set, the git info is displayed in a different color. + # To distinguish between a "fresh" and a "cached" result, the preprompt is rendered before setting this + # variable. Thus, only upon next rendering of the preprompt will the result appear in a different color. + (( $exec_time > 2 )) && prompt_pure_git_last_dirty_check_timestamp=$EPOCHSECONDS ;; prompt_pure_async_git_fetch) prompt_pure_git_arrows=$(prompt_pure_check_git_arrows)