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.
74 lines
2.3 KiB
Bash
74 lines
2.3 KiB
Bash
#!/bin/sh
|
|
|
|
# Regenerate the *-theme.auto.conf files kitty reads at startup from the
|
|
# canonical themes in ./themes, honouring the mode recorded in ./theme-mode:
|
|
#
|
|
# auto every appearance keeps its own theme, so kitty follows the OS
|
|
# light every appearance gets the light theme, so kitty stays light
|
|
# dark every appearance gets the dark theme, so kitty stays dark
|
|
#
|
|
# kitty gives the automatic theme files priority over everything else -- includes
|
|
# and even --override -- so pinning a mode means writing the wanted theme into
|
|
# whichever file the OS makes kitty pick. That is why the real themes live in
|
|
# ./themes and these three files are generated.
|
|
|
|
set -eu
|
|
|
|
script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
|
config_dir=${1:-"$script_dir"}
|
|
canonical_dir="$config_dir/themes"
|
|
mode_file="$config_dir/theme-mode"
|
|
|
|
mode=auto
|
|
if [ -f "$mode_file" ]; then
|
|
mode=$(tr -d ' \t\r\n' < "$mode_file")
|
|
fi
|
|
case "$mode" in
|
|
auto | light | dark) ;;
|
|
*) mode=auto ;;
|
|
esac
|
|
|
|
mkdir -p "$canonical_dir"
|
|
|
|
# Adopt the current automatic themes as canonical when they have not been
|
|
# captured yet. Only safe while following the OS: under a pinned mode the
|
|
# generated files all hold the pinned theme and would overwrite the others.
|
|
if [ "$mode" = auto ]; then
|
|
for appearance in dark light no-preference; do
|
|
canonical="$canonical_dir/$appearance.conf"
|
|
generated="$config_dir/$appearance-theme.auto.conf"
|
|
if [ ! -f "$canonical" ] && [ -f "$generated" ]; then
|
|
cp "$generated" "$canonical"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
for appearance in dark light no-preference; do
|
|
if [ "$mode" = auto ]; then
|
|
source_name=$appearance
|
|
else
|
|
source_name=$mode
|
|
fi
|
|
|
|
canonical="$canonical_dir/$source_name.conf"
|
|
[ -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
|
|
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
|
|
cat "$canonical" > "$tmp"
|
|
chmod "$mode_bits" "$tmp"
|
|
mv -f "$tmp" "$generated"
|
|
trap - EXIT HUP INT TERM
|
|
done
|
|
|
|
"$script_dir/repair-auto-themes.sh" "$config_dir"
|