From d91b0f86f48ef78c446f90b9eb2e5c311e9f80ac Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sun, 1 Dec 2019 18:05:57 +0100 Subject: [PATCH] Repaint all prompts if the variables change This is a good idea in general and simplifies the Classic + VCS prompt. --- .../functions/__fish_config_interactive.fish | 6 ++- .../sample_prompts/classic_vcs.fish | 49 ++++--------------- 2 files changed, 15 insertions(+), 40 deletions(-) diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish index 601d24172..0c9ae3269 100644 --- a/share/functions/__fish_config_interactive.fish +++ b/share/functions/__fish_config_interactive.fish @@ -139,7 +139,11 @@ function __fish_config_interactive -d "Initializations that should be performed # fish_color_cwd{,_root} changes value. Like all event handlers, it can't be # autoloaded. # - function __fish_repaint -v fish_color_cwd -v fish_color_cwd_root -d "Event handler, repaints the prompt when fish_color_cwd* changes" + set -l varargs --on-variable fish_key_bindings + for var in user host cwd{,_root} status + set -a varargs --on-variable fish_color_$var + end + function __fish_repaint $varargs -d "Event handler, repaints the prompt when fish_color_cwd* changes" if status --is-interactive set -e __fish_prompt_cwd commandline -f repaint 2>/dev/null diff --git a/share/tools/web_config/sample_prompts/classic_vcs.fish b/share/tools/web_config/sample_prompts/classic_vcs.fish index 768e782d3..ca141feb1 100644 --- a/share/tools/web_config/sample_prompts/classic_vcs.fish +++ b/share/tools/web_config/sample_prompts/classic_vcs.fish @@ -1,5 +1,5 @@ # name: Classic + Vcs -# author: Kevin Ballard +# author: Lily Ballard # vim: set noet: function fish_prompt --description 'Write out the prompt' @@ -7,44 +7,15 @@ function fish_prompt --description 'Write out the prompt' set -l last_status $status set -l normal (set_color normal) - # Hack; fish_config only copies the fish_prompt function (see #736) - if not set -q -g __fish_classic_git_functions_defined - set -g __fish_classic_git_functions_defined - - function __fish_repaint_user --on-variable fish_color_user --description "Event handler, repaint when fish_color_user changes" - if status --is-interactive - commandline -f repaint 2>/dev/null - end - end - - function __fish_repaint_host --on-variable fish_color_host --description "Event handler, repaint when fish_color_host changes" - if status --is-interactive - commandline -f repaint 2>/dev/null - end - end - - function __fish_repaint_status --on-variable fish_color_status --description "Event handler; repaint when fish_color_status changes" - if status --is-interactive - commandline -f repaint 2>/dev/null - end - end - - function __fish_repaint_bind_mode --on-variable fish_key_bindings --description "Event handler; repaint when fish_key_bindings changes" - if status --is-interactive - commandline -f repaint 2>/dev/null - end - end - - # initialize our new variables - if not set -q __fish_classic_git_prompt_initialized - set -qU fish_color_user - or set -U fish_color_user -o green - set -qU fish_color_host - or set -U fish_color_host -o cyan - set -qU fish_color_status - or set -U fish_color_status red - set -U __fish_classic_git_prompt_initialized - end + # initialize our new variables + if not set -q __fish_classic_git_prompt_initialized + set -qU fish_color_user + or set -U fish_color_user -o green + set -qU fish_color_host + or set -U fish_color_host -o cyan + set -qU fish_color_status + or set -U fish_color_status red + set -U __fish_classic_git_prompt_initialized end set -l color_cwd