dotfiles/scripts/alacritty-sync-system-theme.sh
DannyDannyDanny 74eb3a9c40 feat: rusty-anchor WoL, auto dark/light VT theme, wakeonlan on phantom-ship 🦀
- Enable Wake-on-LAN (magic packet) on rusty-anchor enp2s0 via systemd service
- Add vt-theme script to rusty-anchor: switches between Catppuccin Latte/Mocha
- Theme state persisted in /etc/vt-theme, applied on login via profile.d
- alacritty-sync-system-theme.sh now SSHes to rusty-anchor and pushes the
  macOS light/dark change (best-effort, non-blocking, skips if unchanged)
- Add wakeonlan to phantom-ship packages (wakeonlan 00:16:cb:87:20:ba)
2026-04-04 21:18:44 +02:00

65 lines
2 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"
# Sync theme to rusty-anchor VT console (best-effort, non-blocking)
RUSTY_ANCHOR_KEY="$HOME/.ssh/id_ed25519_phantom_ship"
RUSTY_ANCHOR_THEME_FILE="/etc/vt-theme"
if [[ -f "$RUSTY_ANCHOR_KEY" ]]; then
last_rusty="$ALACRITTY_DIR/.last-rusty-anchor-theme"
if [[ "$(cat "$last_rusty" 2>/dev/null)" != "$want" ]]; then
(
ssh -i "$RUSTY_ANCHOR_KEY" \
-J danny@phantom-ship \
-o ConnectTimeout=5 \
-o StrictHostKeyChecking=no \
danny@10.0.0.2 \
"echo '$want' | sudo tee $RUSTY_ANCHOR_THEME_FILE > /dev/null && sudo /usr/local/bin/vt-theme '$want' /dev/tty1" \
2>/dev/null \
&& printf '%s' "$want" >"$last_rusty"
) &
fi
fi