feat(macos): Alacritty follows system light/dark appearance

New setup — due for review after you run darwin-rebuild switch and
live with it for a few days. See CLAUDE.md (Alacritty) and
assets/alacritty/README.md.

- HM: import active-colors.toml + Catppuccin latte/mocha fragments
- nix-darwin: launchd.user.agents.alacritty-system-theme + PATH helper
- fish: background sync on Darwin; theme.sh no longer rebuilds for Alacritty
- Remove switch-alacritty-theme.sh (sed + darwin-rebuild per toggle)

Made-with: Cursor
This commit is contained in:
DannyDannyDanny 2026-03-23 19:16:05 +01:00
parent 18ccebc109
commit b311e21d5b
15 changed files with 196 additions and 293 deletions

View file

@ -0,0 +1,40 @@
#!/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
if [[ -f "$MARKER" ]] && [[ "$(tr -d '\n' <"$MARKER")" == "$want" ]]; then
exit 0
fi
mkdir -p "$ALACRITTY_DIR"
printf '%s' "$want" >"$MARKER"
if [[ "$want" == "light" ]]; then
cp "$LIGHT" "$ACTIVE"
else
cp "$DARK" "$ACTIVE"
fi

View file

@ -1,27 +1,9 @@
#!/bin/bash
# Simple setup for Alacritty theme synchronization
# This creates the theme file and rebuilds the Nix configuration
# One-shot sync of Alacritty palette + nvim marker from current macOS appearance.
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "Setting up simple Alacritty theme synchronization..."
# Run the theme sync script to create the initial theme file
echo "Detecting current system theme..."
"$SCRIPT_DIR/sync-alacritty-theme.sh"
echo "Syncing from system appearance..."
"$SCRIPT_DIR/alacritty-sync-system-theme.sh"
echo ""
echo "Setup complete!"
echo ""
echo "To apply the theme to Alacritty, run:"
echo " cd nixos && sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air"
echo ""
echo "To sync themes when your system theme changes:"
echo " $SCRIPT_DIR/sync-alacritty-theme.sh && cd nixos && sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air"
echo ""
echo "For automatic theme switching, you can set up a LaunchAgent or"
echo "run the sync script manually when needed."
echo "Done. Alacritty reloads colors automatically if live_config_reload is enabled."
echo "A LaunchAgent (nix-darwin: launchd.user.agents.alacritty-system-theme) runs this every 30s."

View file

@ -1,80 +0,0 @@
#!/bin/bash
# Switch Alacritty theme by updating the Nix configuration
# This script changes the isLightTheme variable in home.nix and rebuilds
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
HOME_NIX="$DOTFILES_DIR/nixos/home/danny/home.nix"
# Check if home.nix exists
if [ ! -f "$HOME_NIX" ]; then
echo "Error: home.nix not found at $HOME_NIX"
exit 1
fi
# Function to switch to light theme
switch_to_light() {
echo "Switching to light theme (Catppuccin Latte)..."
sed -i '' 's/isLightTheme = false;/isLightTheme = true;/' "$HOME_NIX"
}
# Function to switch to dark theme
switch_to_dark() {
echo "Switching to dark theme (Catppuccin Mocha)..."
sed -i '' 's/isLightTheme = true;/isLightTheme = false;/' "$HOME_NIX"
}
# Function to show current theme
show_current() {
if grep -q "isLightTheme = true" "$HOME_NIX"; then
echo "Current theme: Light (Catppuccin Latte)"
else
echo "Current theme: Dark (Catppuccin Mocha)"
fi
}
# Function to rebuild the configuration
rebuild() {
echo "Rebuilding configuration..."
cd "$DOTFILES_DIR/nixos"
sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air
}
# Main logic
case "${1:-}" in
"light")
switch_to_light
rebuild
;;
"dark")
switch_to_dark
rebuild
;;
"toggle")
if grep -q "isLightTheme = true" "$HOME_NIX"; then
switch_to_dark
else
switch_to_light
fi
rebuild
;;
"status"|"current")
show_current
;;
*)
echo "Usage: $0 {light|dark|toggle|status}"
echo ""
echo "Commands:"
echo " light - Switch to light theme (Catppuccin Latte)"
echo " dark - Switch to dark theme (Catppuccin Mocha)"
echo " toggle - Toggle between light and dark themes"
echo " status - Show current theme"
echo ""
show_current
exit 1
;;
esac

View file

@ -1,31 +1,5 @@
#!/bin/bash
# Sync Alacritty theme with system theme
# This script detects the current system theme and updates the theme file that Nix reads
# Back-compat wrapper: sync Alacritty + nvim marker from macOS appearance.
set -e
# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Paths
THEME_DETECTION_SCRIPT="$SCRIPT_DIR/detect-system-theme.sh"
THEME_FILE="/Users/danny/.local/share/nvim_color_scheme"
# Create the directory if it doesn't exist
mkdir -p "$(dirname "$THEME_FILE")"
# Detect current system theme
if [ ! -f "$THEME_DETECTION_SCRIPT" ]; then
echo "Error: Theme detection script not found at $THEME_DETECTION_SCRIPT"
exit 1
fi
CURRENT_THEME=$("$THEME_DETECTION_SCRIPT")
echo "Current system theme: $CURRENT_THEME"
# Write the theme to the file that Nix reads
echo "$CURRENT_THEME" > "$THEME_FILE"
echo "Theme file updated: $THEME_FILE"
echo "Run 'home-manager switch' to apply the new theme to Alacritty"
exec "$SCRIPT_DIR/alacritty-sync-system-theme.sh"

View file

@ -17,7 +17,7 @@ show_usage() {
echo ""
echo "This command switches themes for:"
echo " - Neovim (via nvim_color_scheme file)"
echo " - Alacritty (via Nix configuration on macOS)"
echo " - Alacritty on macOS follows System Settings (LaunchAgent sync)"
echo " - Windows Terminal (via settings.json on WSL)"
echo " - Windows system theme (on WSL)"
}
@ -43,19 +43,11 @@ show_status() {
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo " Platform: macOS"
# Check Alacritty theme from Nix config
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
HOME_NIX="$DOTFILES_DIR/nixos/home/danny/home.nix"
if [ -f "$HOME_NIX" ]; then
if grep -q "isLightTheme = true" "$HOME_NIX"; then
echo " Alacritty: light (Catppuccin Latte)"
else
echo " Alacritty: dark (Catppuccin Mocha)"
fi
marker="$HOME/.config/alacritty/.last-system-theme"
if [ -f "$marker" ]; then
echo " Alacritty: follows system (active palette: $(tr -d '\n' <"$marker"))"
else
echo " Alacritty: config file not found"
echo " Alacritty: follows system (sync after next login or run alacritty-sync-system-theme)"
fi
else
echo " Platform: other"
@ -67,17 +59,10 @@ toggle_theme() {
current_theme=""
if [[ "$OSTYPE" == "darwin"* ]]; then
# On macOS, check the Nix config for current theme
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
HOME_NIX="$DOTFILES_DIR/nixos/home/danny/home.nix"
if [ -f "$HOME_NIX" ]; then
if grep -q "isLightTheme = true" "$HOME_NIX"; then
current_theme="light"
else
current_theme="dark"
fi
if [[ "$(defaults read -g AppleInterfaceStyle 2>/dev/null)" == "Dark" ]]; then
current_theme="dark"
else
current_theme="light"
fi
fi
@ -183,18 +168,8 @@ if [[ -n "$WSL_DISTRO_NAME" ]]; then
powershell.exe -Command "Set-ItemProperty -Path HKCU:\AppEvents\Schemes -Name '(Default)' -Value '.None'"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS platform - handle Alacritty theme
echo "Detected macOS platform"
# Use the existing Alacritty theme switching script
alacritty_script="$DOTFILES_DIR/scripts/switch-alacritty-theme.sh"
if [ -f "$alacritty_script" ]; then
echo "Switching Alacritty theme to: $color_scheme"
"$alacritty_script" "$color_scheme"
else
echo "Warning: Alacritty theme script not found at $alacritty_script"
echo "Theme file updated, but Alacritty theme not switched"
fi
echo "Alacritty follows System Settings → Appearance (no rebuild). Neovim theme file updated above."
else
# Other platforms - just update the theme file