From 826a9417e7fb9278281968cb20a6e1107c160c2e Mon Sep 17 00:00:00 2001 From: Anton Volnuhin Date: Thu, 6 Aug 2026 02:03:13 +0300 Subject: [PATCH] kitty: make the theme mode per-machine theme-mode is a per-machine preference, and the three *-theme.auto.conf files are generated from it plus themes/, so tracking any of them made every machine flag the others' choice. Drop all four from the source state and ignore them. That leaves a freshly applied machine with no theme files for kitty to read, so add run_after_kitty-theme-mode.sh to regenerate them from the canonical themes. It defaults to `auto`, so a new machine follows its OS until told otherwise, and it exits quietly where this kitty config isn't applied rather than failing the run. Since that script now runs on every apply, including on Linux, make the permission lookup in both shell scripts fall back from BSD `stat -f` to GNU `stat -c` and then to 600. --- .chezmoiignore | 9 ++++++ .../kitty/private_dark-theme.auto.conf | 31 ------------------- .../private_executable_apply-theme-mode.sh | 7 ++++- .../private_executable_repair-auto-themes.sh | 5 ++- .../kitty/private_light-theme.auto.conf | 31 ------------------- .../private_no-preference-theme.auto.conf | 31 ------------------- private_dot_config/kitty/theme-mode | 1 - run_after_kitty-theme-mode.sh | 25 +++++++++++++++ 8 files changed, 44 insertions(+), 96 deletions(-) delete mode 100644 private_dot_config/kitty/private_dark-theme.auto.conf delete mode 100644 private_dot_config/kitty/private_light-theme.auto.conf delete mode 100644 private_dot_config/kitty/private_no-preference-theme.auto.conf delete mode 100644 private_dot_config/kitty/theme-mode create mode 100755 run_after_kitty-theme-mode.sh diff --git a/.chezmoiignore b/.chezmoiignore index 08b96bc..61e9808 100644 --- a/.chezmoiignore +++ b/.chezmoiignore @@ -10,3 +10,12 @@ Library # pi: keep config, never commit secrets/sessions .pi/agent/auth.json .pi/agent/sessions + +# kitty: the light/dark mode is per-machine, and the *-theme.auto.conf files +# are generated from it plus .config/kitty/themes. Tracking them would make +# every machine flag the others' mode. run_after_kitty-theme-mode.sh +# regenerates them after apply. +.config/kitty/theme-mode +.config/kitty/dark-theme.auto.conf +.config/kitty/light-theme.auto.conf +.config/kitty/no-preference-theme.auto.conf diff --git a/private_dot_config/kitty/private_dark-theme.auto.conf b/private_dot_config/kitty/private_dark-theme.auto.conf deleted file mode 100644 index fc08e36..0000000 --- a/private_dot_config/kitty/private_dark-theme.auto.conf +++ /dev/null @@ -1,31 +0,0 @@ -background #1c2836 -foreground #ffffff -cursor #bbbbbb -selection_background #b4d5ff -color0 #000000 -color8 #545454 -color1 #f9555f -color9 #fa8b8e -color2 #20af89 -color10 #34bb99 -color3 #fdf029 -color11 #ffff55 -color4 #589cf5 -color12 #589cf5 -color5 #934d95 -color13 #e75598 -color6 #1e9ee6 -color14 #3978bb -color7 #bbbbbb -color15 #ffffff -selection_foreground #1c2836 - -# START_AUTOGENERATED_TAB_STYLE -# Feel free to update these colors manually and remove these comments. -active_tab_foreground #1c2836 -active_tab_background #2e84e6 -inactive_tab_foreground #2e84e6 -inactive_tab_background #1c2836 -# END_AUTOGENERATED_TAB_STYLE - -macos_titlebar_color background diff --git a/private_dot_config/kitty/private_executable_apply-theme-mode.sh b/private_dot_config/kitty/private_executable_apply-theme-mode.sh index 5039f4e..e23f51f 100644 --- a/private_dot_config/kitty/private_executable_apply-theme-mode.sh +++ b/private_dot_config/kitty/private_executable_apply-theme-mode.sh @@ -54,8 +54,13 @@ for appearance in dark light no-preference; do [ -f "$canonical" ] || continue generated="$config_dir/$appearance-theme.auto.conf" + # stat -f is BSD/macOS, stat -c is GNU; this also runs on Linux boxes. mode_bits=600 - [ -f "$generated" ] && mode_bits=$(stat -f '%Lp' "$generated") + if [ -f "$generated" ]; then + mode_bits=$(stat -f '%Lp' "$generated" 2>/dev/null \ + || stat -c '%a' "$generated" 2>/dev/null \ + || echo 600) + fi tmp=$(mktemp "$generated.tmp.XXXXXX") trap 'rm -f "$tmp"' EXIT HUP INT TERM diff --git a/private_dot_config/kitty/private_executable_repair-auto-themes.sh b/private_dot_config/kitty/private_executable_repair-auto-themes.sh index 666492f..d12bc99 100644 --- a/private_dot_config/kitty/private_executable_repair-auto-themes.sh +++ b/private_dot_config/kitty/private_executable_repair-auto-themes.sh @@ -22,7 +22,10 @@ for appearance in dark light no-preference; do trap 'rm -f "$tmp"' EXIT HUP INT TERM awk '$1 != "macos_titlebar_color"' "$config_file" > "$tmp" printf '\nmacos_titlebar_color background\n' >> "$tmp" - chmod "$(stat -f '%Lp' "$config_file")" "$tmp" + # stat -f is BSD/macOS, stat -c is GNU; this also runs on Linux boxes. + chmod "$(stat -f '%Lp' "$config_file" 2>/dev/null \ + || stat -c '%a' "$config_file" 2>/dev/null \ + || echo 600)" "$tmp" mv -f "$tmp" "$config_file" trap - EXIT HUP INT TERM done diff --git a/private_dot_config/kitty/private_light-theme.auto.conf b/private_dot_config/kitty/private_light-theme.auto.conf deleted file mode 100644 index fc08e36..0000000 --- a/private_dot_config/kitty/private_light-theme.auto.conf +++ /dev/null @@ -1,31 +0,0 @@ -background #1c2836 -foreground #ffffff -cursor #bbbbbb -selection_background #b4d5ff -color0 #000000 -color8 #545454 -color1 #f9555f -color9 #fa8b8e -color2 #20af89 -color10 #34bb99 -color3 #fdf029 -color11 #ffff55 -color4 #589cf5 -color12 #589cf5 -color5 #934d95 -color13 #e75598 -color6 #1e9ee6 -color14 #3978bb -color7 #bbbbbb -color15 #ffffff -selection_foreground #1c2836 - -# START_AUTOGENERATED_TAB_STYLE -# Feel free to update these colors manually and remove these comments. -active_tab_foreground #1c2836 -active_tab_background #2e84e6 -inactive_tab_foreground #2e84e6 -inactive_tab_background #1c2836 -# END_AUTOGENERATED_TAB_STYLE - -macos_titlebar_color background diff --git a/private_dot_config/kitty/private_no-preference-theme.auto.conf b/private_dot_config/kitty/private_no-preference-theme.auto.conf deleted file mode 100644 index fc08e36..0000000 --- a/private_dot_config/kitty/private_no-preference-theme.auto.conf +++ /dev/null @@ -1,31 +0,0 @@ -background #1c2836 -foreground #ffffff -cursor #bbbbbb -selection_background #b4d5ff -color0 #000000 -color8 #545454 -color1 #f9555f -color9 #fa8b8e -color2 #20af89 -color10 #34bb99 -color3 #fdf029 -color11 #ffff55 -color4 #589cf5 -color12 #589cf5 -color5 #934d95 -color13 #e75598 -color6 #1e9ee6 -color14 #3978bb -color7 #bbbbbb -color15 #ffffff -selection_foreground #1c2836 - -# START_AUTOGENERATED_TAB_STYLE -# Feel free to update these colors manually and remove these comments. -active_tab_foreground #1c2836 -active_tab_background #2e84e6 -inactive_tab_foreground #2e84e6 -inactive_tab_background #1c2836 -# END_AUTOGENERATED_TAB_STYLE - -macos_titlebar_color background diff --git a/private_dot_config/kitty/theme-mode b/private_dot_config/kitty/theme-mode deleted file mode 100644 index 4520e2f..0000000 --- a/private_dot_config/kitty/theme-mode +++ /dev/null @@ -1 +0,0 @@ -dark diff --git a/run_after_kitty-theme-mode.sh b/run_after_kitty-theme-mode.sh new file mode 100755 index 0000000..1f9a742 --- /dev/null +++ b/run_after_kitty-theme-mode.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +# The kitty *-theme.auto.conf files are generated from .config/kitty/themes and +# the per-machine .config/kitty/theme-mode, both of which .chezmoiignore keeps +# out of the source state. Regenerate them here so a freshly applied machine +# ends up with theme files kitty can read. +# +# apply-theme-mode.sh is idempotent, and defaults to `auto` when there is no +# theme-mode file, so a new machine simply follows its OS until told otherwise. + +set -eu + +config_dir="${KITTY_CONFIG_DIRECTORY:-$HOME/.config/kitty}" +apply="$config_dir/apply-theme-mode.sh" + +# Nothing to do on machines without this kitty config applied. +[ -x "$apply" ] || exit 0 +[ -d "$config_dir/themes" ] || exit 0 + +# Never let a theming problem fail the whole apply. +if ! "$apply" "$config_dir"; then + echo "warning: could not regenerate kitty theme files" >&2 +fi + +exit 0