config/fish/functions/fish_colors.fish

43 lines
2.6 KiB
Fish

function fish_colors --description 'Print the fish color variables'
# Helper function that prints the fish commands needed to set the current colors
function _fish_colors_commands --argument-names _variable_scope
set -l color_list (set -n | grep fish | grep color | grep -v __)
for i in $color_list
echo (string join ' ' -- set $_variable_scope $i $$i)
end
end
# Helper function that prints examples using the current colors
function _fish_colors_examples
set -l color_list (set -n | grep fish | grep color | grep -v __)
set -l normal (set_color normal)
set -l bold (set_color --bold)
echo '┌──────────────────────────────────┬────────────────────────────────────────┬────────────────────────┐'
echo '│ Variable │ Definition │ Example │'
echo '├──────────────────────────────────┼────────────────────────────────────────┼────────────────────────┤'
for variable in $color_list
set -l value $$variable
set -l color (set_color $value 2>/dev/null)
or begin
printf "│ %-32s │ %s%-38s │ %-22s │\n" "$variable" (set_color --bold white --background=red) "$value" "The quick brown fox..."
continue
end
printf "$normal%-32s │ $bold%-38s$normal$color%-22s$normal │\n" "$variable" "$value" "The quick brown fox..."
end
echo '└──────────────────────────────────┴────────────────────────────────────────┴────────────────────────┘'
end
if contains -- '-g' $argv; or contains -- '--global' $argv
_fish_colors_commands '--global'
else if contains -- '-U' $argv; or contains -- '--universal' $argv
_fish_colors_commands '--universal'
else
_fish_colors_examples
end
functions --erase _fish_colors_commands
functions --erase _fish_colors_examples
end