From e8372db781531792932e88247d3d58b8fe4f7385 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 15 Dec 2021 17:59:12 +0100 Subject: [PATCH] completions/set: only show foreground/background colors if relevant Cursory experiments reveal that there are only three color options where the background color is not ignored (though I didn't check all of them). For these three options, the foreground color is ignored. Similar for bold/italics/underline. Teach set completions to only show the colors that won't be ignored. Unrelated observation: we write -a '--background=(set_color --print-colors)' instead of -l background -a '(set_color --print-colors)' because we want all colors to show straight away (there are no other meaningful arguments). --- share/completions/set.fish | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/share/completions/set.fish b/share/completions/set.fish index f52209f03..a88fffe28 100644 --- a/share/completions/set.fish +++ b/share/completions/set.fish @@ -6,14 +6,17 @@ # Various helper functions # -function __fish_set_is_color -d 'Test if We are specifying a color value for the prompt' +function __fish_set_is_color -a foreground background -d 'Test if We are specifying a color value for the prompt' set -l cmd (commandline -poc) set -e cmd[1] for i in $cmd switch $i - + case fish_color_search_match fish_color_selection fish_pager_color_selected_background + $background + return case 'fish_color_*' 'fish_pager_color_*' - return 0 + $foreground + return case '-*' @@ -110,13 +113,13 @@ complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument complete -c set -n '__fish_seen_argument -s e -l erase; and __fish_seen_argument -s l -l local' -f -a "(set -l | string replace ' ' \t'Local Variable: ')" # Color completions -complete -c set -n __fish_set_is_color -x -a '(set_color --print-colors)' -d 'text color' -complete -c set -n __fish_set_is_color -a --background -x -a '(set_color --print-colors)' -complete -c set -n __fish_set_is_color -a --bold -x -complete -c set -n __fish_set_is_color -a --dim -x -complete -c set -n __fish_set_is_color -a --italics -x -complete -c set -n __fish_set_is_color -a --reverse -x -complete -c set -n __fish_set_is_color -a --underline -x +complete -c set -n '__fish_set_is_color true false' -x -a '(set_color --print-colors)' -d 'text color' +complete -c set -n '__fish_set_is_color false true' -a '--background=(set_color --print-colors)' +complete -c set -n '__fish_set_is_color true false' -a --bold -x +complete -c set -n '__fish_set_is_color true false' -a --dim -x +complete -c set -n '__fish_set_is_color true false' -a --italics -x +complete -c set -n '__fish_set_is_color true true' -a --reverse -x +complete -c set -n '__fish_set_is_color true false' -a --underline -x # Locale completions complete -c set -n '__fish_set_is_locale; and not __fish_seen_argument -s e -l erase' -x -a '(command -sq locale; and locale -a)' -d Locale