dotfiles/scripts/alacritty-sync-system-theme.sh
DannyDannyDanny 1c7794e904 fix: remove rusty-anchor Mac dependency from alacritty-sync-system-theme 🧹
rusty-anchor now switches themes independently via systemd timer + sunrise-sunset
API — no longer needs the Mac to push changes over SSH
2026-04-06 10:37:38 +02:00

46 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Keep Alacritty in sync with macOS light/dark appearance.
# No Nix rebuild: copies a palette into active-colors.toml; Alacritty reloads via live_config_reload.
set -euo pipefail
[[ "$(uname -s)" == "Darwin" ]] || exit 0
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
ALACRITTY_DIR="$XDG_CONFIG_HOME/alacritty"
ACTIVE="$ALACRITTY_DIR/active-colors.toml"
MARKER="$ALACRITTY_DIR/.last-system-theme"
LIGHT="$ALACRITTY_DIR/catppuccin-latte-colors.toml"
DARK="$ALACRITTY_DIR/catppuccin-mocha-colors.toml"
if [[ ! -f "$LIGHT" || ! -f "$DARK" ]]; then
echo "alacritty-sync-system-theme: missing $LIGHT or $DARK (run home-manager switch first)" >&2
exit 1
fi
appearance="$(defaults read -g AppleInterfaceStyle 2>/dev/null || true)"
if [[ "$appearance" == "Dark" ]]; then
want="dark"
else
want="light"
fi
mkdir -p "$ALACRITTY_DIR"
printf '%s' "$want" >"$MARKER"
# Neovim (see nixos/neovim.nix): same file as `theme` on WSL; keep in sync with Appearance.
NVIM_THEME="${XDG_DATA_HOME:-$HOME/.local/share}/nvim_color_scheme"
mkdir -p "$(dirname "$NVIM_THEME")"
printf '%s\n' "$want" >"$NVIM_THEME"
if [[ "$want" == "light" ]]; then
tmp="$(mktemp "$ALACRITTY_DIR/active-colors.toml.XXXXXX")"
cp "$LIGHT" "$tmp"
else
tmp="$(mktemp "$ALACRITTY_DIR/active-colors.toml.XXXXXX")"
cp "$DARK" "$tmp"
fi
chmod 0644 "$tmp"
mv -f "$tmp" "$ACTIVE"