fish_config theme choose: overwrite color-aware theme's vars also if called from config

Webconfig persists themes to ~/.config/fish/conf.d/fish_frozen_theme.fish
(the name is due to historical reasons).

That file's color variables have no "--theme=foo" annotations, which
means that fish_config can't distinguish them from other "user-set"
values.  We can change this in future, but that doesn't affect the
following fix.

A "fish_config theme choose foo" command is supposed to
overwrite all variables that are defined in "foo.theme".
If the theme is color-theme-aware *and* this command runs before
$fish_terminal_color_theme is initialized, we delay loading of the
theme until that initialization happens.  But the --on-variable
invocation won't have the override bit set, thus it will not touch
variables that don't have "--theme=*" value.  Fix this by clearing
immediately the variables mentioned in the theme.

Fixes #12278

While at it, tweak the error message for this command because it's
not an internal error:

	fish -c 'echo yes | fish_config theme save tomorrow'
This commit is contained in:
Johannes Altmanninger
2026-01-06 08:48:18 +01:00
parent c638401469
commit 6d8bb292ec
3 changed files with 48 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
# RUN: %fish %s
# REQUIRES: command -v diff
set -g fish (status fish-path)
fish_config prompt list | string match -r '^(?:acidhub|disco|nim)$'
# CHECK: acidhub
# CHECK: disco
@@ -218,5 +220,31 @@ echo >$__fish_config_dir/themes/custom-from-userconf.theme \
# CHECK: $fish_color_normal[1]: |normal|
}
{
echo >$__fish_config_dir/conf.d/fish_frozen_theme.fish "\
set --global fish_color_command 0a0a0a
set --global fish_color_option 0b0b0b"
echo >$__fish_config_dir/themes/from-cli.theme "\
[light]
fish_color_command black
fish_color_param 0c0c0c
[dark]
fish_color_command white
fish_color_param c0c0c0"
$fish -c '
fish_config theme choose from-cli
echo $fish_color_command
# CHECK: --theme=from-cli
echo $fish_color_option
# CHECK: 0b0b0b
echo $fish_color_param
# CHECK: --theme=from-cli
echo yes | fish_config theme save from-cli
# CHECKERR: fish_config theme save: error: $fish_terminal_color_theme not yet initialized
and echo assertion failure
'
rm -f $__fish_config_dir/conf.d/fish_frozen_theme.fish
}
fish_config theme dump badarg
# CHECKERR: Too many arguments