feat(functions): derive the shared help palette from the fish theme

__fish_palette's c_cmd/c_flag/c_arg/c_dim now read fish's own highlighter
variables (fish_color_command/option/param/autosuggestion) when set, and
c_head reads the pager's fish_pager_color_prefix, so --help text matches
whatever the user's actual theme renders at the prompt instead of a fixed
guess at it. Each role keeps its previous static value as a fallback
(e.g. a --no-config script, or the theme variable being unset or empty).

Routes __fish_help_header's title/section colors and config-help's,
gi's, and git-clean's own hand-rolled --help blocks through the palette
instead of their hardcoded set_color calls, which fixes the
--help-vs-actual-prompt color mismatch across most of the config's
functions in one place (__fish_help_header backs the majority of
user-facing --help output).

Also fixes role mismatches found along the way: several already-palette
functions (dockup, fish-deps, pkg, play-media, dng2avif) were coloring
their <placeholder>/[bracket] argument text with c_dim instead of c_arg,
and scrub's "Aggressive Targets:" heading was still a hardcoded
set_color call sitting next to an otherwise-converted help block.
This commit is contained in:
2026-09-21 01:19:38 -04:00
parent 02c060f9f1
commit 610714476d
11 changed files with 103 additions and 96 deletions
+4 -3
View File
@@ -45,9 +45,10 @@ function __fish_help_header --argument-names name
# First argument only -- see DESCRIPTION.
contains -- "$argv[2]" -h --help; or return 1
set -l c_ttl (set_color --bold)
set -l c_sec (set_color --bold brblue)
set -l c_rst (set_color normal)
__fish_palette
set -l c_ttl $c_cmd
set -l c_sec $c_head
set -l c_rst $c_reset
set -l miss " No documentation header found. Try: help config $name"
set -l file (functions -D -- $name 2>/dev/null)
+28 -9
View File
@@ -19,11 +19,18 @@
# TERM=dumb, which yields empty strings, and is unaffected by whether
# stdout is a tty or a pipe.)
#
# A role is a semantic slot, not a colour. c_flag and c_warn are both
# yellow but stay separate, as do c_ok and c_accent (both green) --
# merging either pair would foreclose ever restyling one without the
# other. c_accent is the command name in logs and smart_exit, which
# style it green where the rest of the config styles it bold.
# A role is a semantic slot, not a colour. c_flag and c_warn can both be
# yellow but stay separate, as do c_ok and c_accent -- merging either
# pair would foreclose ever restyling one without the other. c_accent is
# the command name in logs and smart_exit, which style it green where
# the rest of the config styles it bold.
#
# c_cmd, c_flag, c_arg, and c_dim are drawn from fish's own highlighter
# variables (fish_color_command/option/param/autosuggestion) when set,
# and c_head from the pager's fish_pager_color_prefix -- the same colour
# a real command, flag, argument, or pager heading gets at the prompt.
# Each falls back to its previous static default when the theme
# variable is unset or empty (e.g. a --no-config script).
#
# ARGUMENTS
# none
@@ -49,15 +56,27 @@
function __fish_palette --no-scope-shadowing --description 'Define the shared output colour palette in the caller scope'
set c_reset (set_color normal)
set c_head (set_color --bold cyan)
set c_cmd (set_color --bold)
set c_cmd (set_color brblue)
set c_flag (set_color brgreen)
set c_arg (set_color cyan)
set c_flag (set_color yellow)
set c_dim (set_color brblack)
set c_head (set_color --bold cyan)
set c_warn (set_color yellow)
set c_err (set_color red)
set c_ok (set_color green)
set c_accent (set_color green)
set c_dim (set_color brblack)
set c_sel (set_color --bold magenta)
set c_hi (set_color --bold white)
# Theme overrides: same roles fish's own highlighter/pager use, so
# --help text matches the prompt instead of a fixed guess at it.
set -l roles command option param autosuggestion
set -l vars c_cmd c_flag c_arg c_dim
for i in (seq (count $roles))
set -l themevar fish_color_$roles[$i]
set -q $themevar; and test (count $$themevar) -gt 0
and set $vars[$i] (set_color $$themevar)
end
set -q fish_pager_color_prefix; and test (count $fish_pager_color_prefix) -gt 0
and set c_head (set_color --bold $fish_pager_color_prefix)
end
+35 -46
View File
@@ -190,63 +190,52 @@ function config-help --description 'Open the offline fish shell configuration ma
# ── --help / -h ──────────────────────────────────────────────
if contains -- --help $argv; or contains -- -h $argv
set_color --bold
echo "help config / config-help"
set_color normal
__fish_palette
echo "$c_cmd""help config / config-help$c_reset"
echo " — view the offline fish shell configuration manual"
echo ""
set_color --bold brblue
echo USAGE
set_color normal
echo " help config "(set_color yellow)"[section]"(set_color normal)
echo " help config "(set_color yellow)"[section] --html"(set_color normal)
echo " help config "(set_color yellow)"[section] --man"(set_color normal)
echo " help config "(set_color yellow)"--help"(set_color normal)
echo "$c_head""USAGE$c_reset"
echo " help config $c_arg""[section]$c_reset"
echo " help config $c_arg""[section]$c_reset $c_flag--html$c_reset"
echo " help config $c_arg""[section]$c_reset $c_flag--man$c_reset"
echo " help config $c_flag--help$c_reset"
echo ""
set_color --bold brblue
echo ARGUMENTS
set_color normal
echo " "(set_color yellow)"section"(set_color normal)" Optional keyword to jump to a matching section heading."
echo "$c_head""ARGUMENTS$c_reset"
echo " $c_arg""section$c_reset Optional keyword to jump to a matching section heading."
echo " Searches docs/fish-config.index for aliases first, then"
echo " falls back to a normalized (case- and punctuation-insensitive)"
echo " scan of heading lines."
echo " "(set_color yellow)"-w, --html"(set_color normal)" Open the published documentation website in the default browser."
echo " $c_flag-w, --html$c_reset Open the published documentation website in the default browser."
echo " Deep links aren't supported — use the site's search box."
echo " "(set_color yellow)"-m, --man"(set_color normal)" Open the compiled man page via man -l."
echo " $c_flag-m, --man$c_reset Open the compiled man page via man -l."
echo " If a section keyword is given, jumps to the nearest match."
echo ""
set_color --bold brblue
echo EXAMPLES
set_color normal
echo " "(set_color green)"help config"(set_color normal)" open at top"
echo " "(set_color green)"help config keybindings"(set_color normal)" jump to Key Bindings section"
echo " "(set_color green)"help config pkg"(set_color normal)" jump to the pkg function entry"
echo " "(set_color green)"help config fish-deps"(set_color normal)" jump to fish-deps"
echo " "(set_color green)"help config abbreviations"(set_color normal)" jump to Abbreviations section"
echo " "(set_color green)"help config --html"(set_color normal)" open the documentation website"
echo " "(set_color green)"help config --man"(set_color normal)" open compiled man page"
echo " "(set_color green)"help config pkg --man"(set_color normal)" open man page at pkg section"
echo "$c_head""EXAMPLES$c_reset"
echo " $c_cmd""help config$c_reset open at top"
echo " $c_cmd""help config$c_reset $c_arg""keybindings$c_reset jump to Key Bindings section"
echo " $c_cmd""help config$c_reset $c_arg""pkg$c_reset jump to the pkg function entry"
echo " $c_cmd""help config$c_reset $c_arg""fish-deps$c_reset jump to fish-deps"
echo " $c_cmd""help config$c_reset $c_arg""abbreviations$c_reset jump to Abbreviations section"
echo " $c_cmd""help config$c_reset $c_flag--html$c_reset open the documentation website"
echo " $c_cmd""help config$c_reset $c_flag--man$c_reset open compiled man page"
echo " $c_cmd""help config$c_reset $c_arg""pkg$c_reset $c_flag--man$c_reset open man page at pkg section"
echo ""
set_color --bold brblue
echo "NAVIGATION (ov pager)"
set_color normal
echo " "(set_color cyan)"Space"(set_color normal)" next section"
echo " "(set_color cyan)"^"(set_color normal)" previous section"
echo " "(set_color cyan)"Alt+u"(set_color normal)" toggle section list sidebar"
echo " "(set_color cyan)"/"(set_color normal)" search forward"
echo " "(set_color cyan)"n"(set_color normal)" / "(set_color cyan)"N"(set_color normal)" next / previous search match"
echo " "(set_color cyan)"g"(set_color normal)" go to line number"
echo " "(set_color cyan)"q"(set_color normal)" quit"
echo "$c_head""NAVIGATION (ov pager)$c_reset"
echo " $c_arg""Space$c_reset next section"
echo " $c_arg""^$c_reset previous section"
echo " $c_arg""Alt+u$c_reset toggle section list sidebar"
echo " $c_arg""/$c_reset search forward"
echo " $c_arg""n$c_reset / $c_arg""N$c_reset next / previous search match"
echo " $c_arg""g$c_reset go to line number"
echo " $c_arg""q$c_reset quit"
echo ""
set_color --bold brblue
echo "PAGER FALLBACK CHAIN"
set_color normal
echo " "(set_color brblack)"1."(set_color normal)" ov + bat section nav + syntax highlighting "(set_color brblack)"(best)"(set_color normal)
echo " "(set_color brblack)"2."(set_color normal)" ov alone section nav, raw Markdown"
echo " "(set_color brblack)"3."(set_color normal)" bat alone syntax highlighting, use / to search"
echo " "(set_color brblack)"4."(set_color normal)" man -l pre-compiled man page (if available)"
echo " "(set_color brblack)"5."(set_color normal)" less plain text with line-jump"
echo " "(set_color brblack)"6."(set_color normal)" cat plain output"
echo "$c_head""PAGER FALLBACK CHAIN$c_reset"
echo " $c_dim""1.$c_reset ov + bat section nav + syntax highlighting $c_dim""(best)$c_reset"
echo " $c_dim""2.$c_reset ov alone section nav, raw Markdown"
echo " $c_dim""3.$c_reset bat alone syntax highlighting, use / to search"
echo " $c_dim""4.$c_reset man -l pre-compiled man page (if available)"
echo " $c_dim""5.$c_reset less plain text with line-jump"
echo " $c_dim""6.$c_reset cat plain output"
return 0
end
+5 -5
View File
@@ -39,13 +39,13 @@ function dng2avif --description 'Convert DNG raw to 10-bit HDR AVIF'
# Help Screen
if set -q _flag_help; or test (count $argv) -eq 0 -a -z "$_flag_input"
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""dng2avif$c_reset $c_flag""[options]$c_reset $c_dim""[input.dng]$c_reset"
echo "$c_head""Usage:$c_reset $c_cmd""dng2avif$c_reset $c_flag""[options]$c_reset $c_arg""[input.dng]$c_reset"
echo ""
echo "$c_head""Options:$c_reset"
echo " $c_flag-i$c_reset, $c_flag--input$c_reset $c_dim""FILE$c_reset Input DNG file"
echo " $c_flag-o$c_reset, $c_flag--output$c_reset $c_dim""FILE$c_reset Output AVIF file (defaults to input name)"
echo " $c_flag-q$c_reset, $c_flag--quality$c_reset $c_dim""N$c_reset Encoding quality 0-100 (default: 92)"
echo " $c_flag-s$c_reset, $c_flag--speed$c_reset $c_dim""N$c_reset Encoder speed 0-10 (default: 3, 0=slowest)"
echo " $c_flag-i$c_reset, $c_flag--input$c_reset $c_arg""FILE$c_reset Input DNG file"
echo " $c_flag-o$c_reset, $c_flag--output$c_reset $c_arg""FILE$c_reset Output AVIF file (defaults to input name)"
echo " $c_flag-q$c_reset, $c_flag--quality$c_reset $c_arg""N$c_reset Encoding quality 0-100 (default: 92)"
echo " $c_flag-s$c_reset, $c_flag--speed$c_reset $c_arg""N$c_reset Encoder speed 0-10 (default: 3, 0=slowest)"
echo " $c_flag-h$c_reset, $c_flag--help$c_reset Show this help message"
return 0
end
+2 -2
View File
@@ -31,13 +31,13 @@ function dockup --description 'Pull and restart docker compose containers'
# Handle help flags
if contains -- -h $argv; or contains -- --help $argv
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""dockup$c_reset $c_dim""[DIRECTORY]$c_reset"
echo "$c_head""Usage:$c_reset $c_cmd""dockup$c_reset $c_arg""[DIRECTORY]$c_reset"
echo ""
echo "$c_head""Options:$c_reset"
echo " $c_flag-h$c_reset, $c_flag--help$c_reset Show this help message"
echo ""
echo "$c_head""Arguments:$c_reset"
echo " $c_dim""DIRECTORY$c_reset Optional path to the compose project (defaults to current dir)"
echo " $c_arg""DIRECTORY$c_reset Optional path to the compose project (defaults to current dir)"
return 0
end
+1 -1
View File
@@ -105,7 +105,7 @@ function __fish_deps_help
echo "$c_head""fish-deps$c_reset — manage fish shell dependencies"
echo ""
echo "$c_head""Usage:$c_reset"
echo " $c_cmd""fish-deps$c_reset $c_dim""[status]$c_reset Check installed/missing deps (default)"
echo " $c_cmd""fish-deps$c_reset $c_arg""[status]$c_reset Check installed/missing deps (default)"
echo " $c_cmd""fish-deps$c_reset install Install missing deps interactively"
echo " $c_cmd""fish-deps$c_reset update Update all installed deps"
echo " $c_cmd""fish-deps$c_reset sync Install missing, then update all"
+20 -23
View File
@@ -39,32 +39,29 @@ function gi --description 'Generate .gitignore files using the gitignore.io API'
or return 1
if set -q _flag_help
set_color --bold
echo "Usage:"(set_color normal)" gi "(set_color cyan)"[TARGETS...]"(set_color yellow)" [FLAGS]"(set_color normal)
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""gi$c_reset $c_arg""[TARGETS...]$c_reset $c_arg""[FLAGS]$c_reset"
echo ""
set_color --bold
echo "Arguments:"(set_color normal)
echo " "(set_color cyan)"TARGETS"(set_color normal)" Comma-separated list of languages or tools"
echo " "(set_color brblack)"e.g. c++,neovim,archlinux"(set_color normal)
echo "$c_head""Arguments:$c_reset"
echo " $c_arg""TARGETS$c_reset Comma-separated list of languages or tools"
echo " $c_dim""e.g. c++,neovim,archlinux$c_reset"
echo ""
set_color --bold
echo "Flags:"(set_color normal)
echo " "(set_color yellow)"-h, --help "(set_color normal)" Show this help message"
echo " "(set_color yellow)"-d, --description "(set_color normal)" Show the Fish function description"
echo " "(set_color yellow)"-l, --list "(set_color normal)" List all supported targets from the API"
echo " "(set_color yellow)"-b, --boilerplate "(set_color normal)" Append boilerplate from "(set_color cyan)"\$GITIGNORE_BOILERPLATE"(set_color normal)" to .gitignore"
echo " "(set_color yellow)"-p, --prompt "(set_color normal)" Prompt for patterns and append them to .gitignore"
echo " "(set_color yellow)"-s, --stdout "(set_color normal)" Print API output to stdout instead of appending to .gitignore"
echo "$c_head""Flags:$c_reset"
echo " $c_flag-h, --help $c_reset Show this help message"
echo " $c_flag-d, --description $c_reset Show the Fish function description"
echo " $c_flag-l, --list $c_reset List all supported targets from the API"
echo " $c_flag-b, --boilerplate $c_reset Append boilerplate from $c_arg""\$GITIGNORE_BOILERPLATE$c_reset to .gitignore"
echo " $c_flag-p, --prompt $c_reset Prompt for patterns and append them to .gitignore"
echo " $c_flag-s, --stdout $c_reset Print API output to stdout instead of appending to .gitignore"
echo ""
set_color --bold
echo "Examples:"(set_color normal)
echo " "(set_color green)"gi"(set_color normal)" "(set_color brblack)"# Append boilerplate and prompt for patterns (default)"(set_color normal)
echo " "(set_color green)"gi -b"(set_color normal)" "(set_color brblack)"# Append boilerplate only"(set_color normal)
echo " "(set_color green)"gi -p"(set_color normal)" "(set_color brblack)"# Prompt for patterns and append to .gitignore"(set_color normal)
echo " "(set_color green)"gi"(set_color normal)" "(set_color cyan)"c++"(set_color normal)" "(set_color brblack)"# Append C++ patterns to .gitignore"(set_color normal)
echo " "(set_color green)"gi"(set_color normal)" "(set_color cyan)"python,venv"(set_color normal)" "(set_color brblack)"# Append Python+venv patterns to .gitignore"(set_color normal)
echo " "(set_color green)"gi -s"(set_color normal)" "(set_color cyan)"python,venv"(set_color normal)" "(set_color brblack)"# Print Python+venv patterns to stdout"(set_color normal)
echo " "(set_color green)"gi -l"(set_color normal)" | grep -i linux "(set_color brblack)"# Search for specific OS support"(set_color normal)
echo "$c_head""Examples:$c_reset"
echo " $c_cmd""gi$c_reset $c_dim""# Append boilerplate and prompt for patterns (default)$c_reset"
echo " $c_cmd""gi -b$c_reset $c_dim""# Append boilerplate only$c_reset"
echo " $c_cmd""gi -p$c_reset $c_dim""# Prompt for patterns and append to .gitignore$c_reset"
echo " $c_cmd""gi$c_reset $c_arg""c++$c_reset $c_dim""# Append C++ patterns to .gitignore$c_reset"
echo " $c_cmd""gi$c_reset $c_arg""python,venv$c_reset $c_dim""# Append Python+venv patterns to .gitignore$c_reset"
echo " $c_cmd""gi -s$c_reset $c_arg""python,venv$c_reset $c_dim""# Print Python+venv patterns to stdout$c_reset"
echo " $c_cmd""gi -l$c_reset | grep -i linux $c_dim""# Search for specific OS support$c_reset"
return 0
end
+3 -2
View File
@@ -29,9 +29,10 @@ function git-clean --description 'Sync main, prune remotes, and delete orphaned
or return
if set -q _flag_help
echo (set_color --bold blue)"Usage: "(set_color normal)"git-clean [OPTIONS]"
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""git-clean$c_reset $c_arg""[OPTIONS]$c_reset"
echo
echo "Steps taken:"
echo "$c_head""Steps taken:$c_reset"
echo " 1. Fetches and prunes to find deleted remote branches."
echo " 2. Switches to main if you are on an orphaned branch."
echo " 3. Pulls the latest changes from the remote."
+2 -2
View File
@@ -73,7 +73,7 @@ function pkg --description 'Install or remove packages via the system package ma
switch $arg
case -h --help
echo "$c_head""Usage:$c_reset $c_cmd""pkg$c_reset " \
"$c_flag""[-h] [-i] [-u]$c_reset $c_dim""<package>...$c_reset"
"$c_flag""[-h] [-i] [-u]$c_reset $c_arg""<package>...$c_reset"
echo
echo " Install or remove packages via $pm."
echo
@@ -107,7 +107,7 @@ function pkg --description 'Install or remove packages via the system package ma
if test (count $packages) -eq 0
echo "$c_head""Usage:$c_reset $c_cmd""pkg$c_reset " \
"$c_flag""[-h] [-i] [-u]$c_reset $c_dim""<package>...$c_reset"
"$c_flag""[-h] [-i] [-u]$c_reset $c_arg""<package>...$c_reset"
echo
echo " Install or remove packages via $pm."
echo
+2 -2
View File
@@ -42,12 +42,12 @@ function play-media --description 'Pick audio/video files with fzf and play them
or return 1
if set -q _flag_help
echo "$c_head""Usage:$c_reset $c_cmd""play-media$c_reset $c_flag""[-p|--player$c_reset $c_dim<cmd>$c_reset""$c_flag]$c_reset"
echo "$c_head""Usage:$c_reset $c_cmd""play-media$c_reset $c_flag""[-p|--player$c_reset $c_arg<cmd>$c_reset""$c_flag]$c_reset"
echo
echo " Pick audio/video files under the current directory with fzf and play them."
echo
echo "$c_head""Options:$c_reset"
echo " $c_flag-p$c_reset, $c_flag--player$c_reset $c_dim<cmd>$c_reset Force a specific player command"
echo " $c_flag-p$c_reset, $c_flag--player$c_reset $c_arg<cmd>$c_reset Force a specific player command"
echo " $c_flag-h$c_reset, $c_flag--help$c_reset Show this help"
return 0
end
+1 -1
View File
@@ -79,7 +79,7 @@ function scrub --description 'Recursively purge OS, editor, and compiler garbage
echo " • Compiles: core.[0-9]+ (Linux core dumps)"
echo " • Slicers: *.gcode.tmp, *.gcode.bak, .bambu_bak"
echo
echo (set_color --bold yellow)"Aggressive Targets:"(set_color normal)
echo "$c_head""Aggressive Targets:$c_reset"
echo " • Heavy Caches: node_modules, .vagrant"
echo " • Extra Cruft: *.class, *.log, *.log.[0-9]+, Thumbs.db:encryptable"
echo " • IDE/Git Junk: .idea, .clwb, .git-crypt"