`theme` switches kitty between the existing dark-theme.auto.conf and light-theme.auto.conf via `kitty @ set-colors --all --configured`, so it stays in sync with whatever `kitten themes --light/--dark` selects. Subcommands: light, dark, auto (hand control back to the OS appearance via load-config), status. Tide is resynced by calling __tide_apply_terminal_appearance directly, so the prompt recolors even if kitty sends no palette-change notification for a dynamic color change. conf.d/kitty_theme.fish tracks $fish_terminal_color_theme into $kitty_theme_mode so the toggle still reads the real state after kitty follows an OS appearance change. light-theme.auto.conf had no tab colors, which left the dark tab bar on a light background after switching; add a matching tab style block.
92 lines
2.8 KiB
Fish
92 lines
2.8 KiB
Fish
function theme --description 'Switch kitty between its light and dark color themes'
|
|
set -l config_dir $HOME/.config/kitty
|
|
set -q KITTY_CONFIG_DIRECTORY
|
|
and set config_dir $KITTY_CONFIG_DIRECTORY
|
|
|
|
if test (count $argv) -gt 1
|
|
echo "theme: expected at most one argument" >&2
|
|
return 2
|
|
end
|
|
|
|
set -l target $argv[1]
|
|
test -z "$target"
|
|
and set target toggle
|
|
|
|
switch $target
|
|
case -h --help help
|
|
printf '%s\n' \
|
|
'Usage: theme [light|dark|auto|status]' \
|
|
'' \
|
|
' theme toggle between light and dark' \
|
|
' theme light switch to light' \
|
|
' theme dark switch to dark' \
|
|
' theme auto follow the macOS appearance again' \
|
|
' theme status print the current mode'
|
|
return 0
|
|
case status
|
|
__kitty_theme_current
|
|
return 0
|
|
case toggle
|
|
if test (__kitty_theme_current) = dark
|
|
set target light
|
|
else
|
|
set target dark
|
|
end
|
|
case auto light dark
|
|
# handled below
|
|
case '*'
|
|
echo "theme: unknown mode '$target' (expected light, dark, auto or status)" >&2
|
|
return 2
|
|
end
|
|
|
|
if not set -q KITTY_WINDOW_ID
|
|
echo "theme: not running inside kitty" >&2
|
|
return 1
|
|
end
|
|
|
|
if test "$target" = auto
|
|
# Re-reading the config restores kitty's own OS-appearance handling,
|
|
# which a manual override suppresses until the OS appearance changes.
|
|
kitty @ load-config
|
|
or return $status
|
|
|
|
if test "$(defaults read -g AppleInterfaceStyle 2>/dev/null)" = Dark
|
|
set target dark
|
|
else
|
|
set target light
|
|
end
|
|
else
|
|
set -l theme_file $config_dir/$target-theme.auto.conf
|
|
if not test -r $theme_file
|
|
echo "theme: cannot read $theme_file" >&2
|
|
return 1
|
|
end
|
|
|
|
# Only pass through settings whose value is a hex color; kitty's
|
|
# set-colors rejects everything else these files may contain.
|
|
set -l colors (awk 'NF == 2 && $1 !~ /^#/ && $2 ~ /^#[0-9a-fA-F]+$/ { print $1 "=" $2 }' $theme_file)
|
|
if test (count $colors) -eq 0
|
|
echo "theme: no colors found in $theme_file" >&2
|
|
return 1
|
|
end
|
|
|
|
kitty @ set-colors --all --configured $colors
|
|
or return $status
|
|
end
|
|
|
|
set --universal kitty_theme_mode $target
|
|
|
|
if functions -q __tide_apply_terminal_appearance
|
|
__tide_apply_terminal_appearance $target
|
|
set -l apply_status $status
|
|
if test $apply_status -eq 0
|
|
functions -q _tide_cache_variables
|
|
and _tide_cache_variables
|
|
functions -q _tide_sub_reload
|
|
and tide reload
|
|
end
|
|
end
|
|
|
|
echo $target
|
|
end
|