From 02237fd0b11c0d0b5a21f890c772485030f255d0 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 18 Dec 2021 04:46:02 +0100 Subject: [PATCH] Don't re-run work_directory function - Re-reunning work_directory every time we redraw the prompt isn't necessary, since the function is here to generate the zsh supported syntax for the prompt that will get expanded into a work directory automatically. - The function is only here to determine whether we're in TTY and use ASCII compatible symbols if we are, however it is enough to only check this once initially, since we can't leave TTY in favor of a graphical instance without reloading the rc file and neither can we leave. - However, this function also checks for `USE_SHORTENED_WORKDIR` variable and decides which prompt to show based on it. This means that it someone was setting this variable in their profile file it would now no longer be respected, however this was never the intention of that variable, if a change is desired, the variable should simply be edited in the prompt file directly. - Removing continual calls to this function each time prompt is redrawn is worth the very minor inconvenience of no longer supporting shortened workdirs from externally set variable due to the speed benefit it gives us, though not that noticeable, it is pretty significant. Not to mention that this wasn't intended/recommended usage anyway. --- home/.config/shell/prompt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/home/.config/shell/prompt b/home/.config/shell/prompt index 2781bfe..b41a618 100755 --- a/home/.config/shell/prompt +++ b/home/.config/shell/prompt @@ -66,7 +66,7 @@ foreign_prompt() { fi } -# Prints appropriate working directory +#nd Prints appropriate working directory working_directory() { # By default up to 5 directories will be tolerated before shortening # After we surpass that, first directory (or ~) will be printed together with last 3 @@ -148,7 +148,7 @@ add-zsh-hook precmd exec_time_precmd_hook # Primary Prompt [ "$EUID" -eq 0 ] && PS1="$RED%n$RESET" || PS1="$GREEN%n$RESET" # user PS1+="$(foreign_prompt)" -PS1+="\$(working_directory)" +PS1+="$(working_directory)" PS1+="\$(git_prompt)" PS1+="\$(display_cmd_time)" PS1+=" $PURPLE%(!.#.$)$RESET " # Final symbol (# or $)