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

@ -1,102 +1,54 @@
# Unified Theme Switching
# Alacritty + system appearance (macOS)
Unified theme switching that works across platforms (WSL and macOS) for Neovim, Alacritty, and Windows Terminal.
Alacritty follows **System Settings → Appearance** automatically. No `darwin-rebuild` when you change light/dark.
**This solution uses a single `theme` command that detects the platform and switches themes appropriately.**
## How it works
## How It Works
1. Home Manager installs Catppuccin palettes as `~/.config/alacritty/catppuccin-{latte,mocha}-colors.toml` and a generated `alacritty.toml` that sets `general.import` to `active-colors.toml`.
2. `scripts/alacritty-sync-system-theme.sh` copies the matching palette to `active-colors.toml`. Alacrittys `live_config_reload` picks it up immediately.
3. **nix-darwin** runs that script from a user LaunchAgent every 30s (`nixos/hosts/macos.nix`: `launchd.user.agents.alacritty-system-theme`). It is also installed on `PATH` as `alacritty-sync-system-theme`.
4. **Fish** runs the same script in the background when you open an interactive shell on Darwin, so changes apply quickly without waiting for the next poll.
1. The `theme` command detects the platform (WSL vs macOS)
2. **On WSL:** Updates Neovim, Windows Terminal, and Windows system theme
3. **On macOS:** Updates Neovim and Alacritty themes via Nix configuration
4. Uses the same `nvim_color_scheme` file for Neovim on both platforms
## Optional manual LaunchAgent
## Setup
If you are not using the nix-darwin agent, you can load `assets/launchd/com.user.alacritty-theme-sync.plist` (adjust paths if needed). **Do not** load both the nix-darwin agent and this plist or you will run two pollers.
1. **The configuration is already set up!** The `theme` command is available as a fish alias.
If you previously used the old plist label `com.user.alacritty-theme-sync` and switch to nix-darwin only:
2. **To switch themes, use the unified command:**
```bash
theme light # Switch to light theme
theme dark # Switch to dark theme
theme toggle # Toggle between light and dark themes
theme status # Show current theme status
```
## Usage
### Unified Theme Command
```bash
# Switch to light theme (works on WSL and macOS)
theme light
launchctl bootout "gui/$(id -u)" ~/Library/LaunchAgents/com.user.alacritty-theme-sync.plist 2>/dev/null || true
```
# Switch to dark theme (works on WSL and macOS)
## `theme` command (Neovim / WSL)
The fish alias `theme` still updates `~/.local/share/nvim_color_scheme` (and Windows Terminal on WSL). On macOS, **Alacritty ignores** `theme light|dark` for terminal colors—it only follows System Settings. Neovim stays on whatever you set with `theme`; the Alacritty sync script does not touch the nvim file.
```bash
theme light # Neovim (+ WSL terminal); macOS Alacritty unchanged (uses Appearance)
theme dark
# Toggle between light and dark themes
theme toggle
# Show current theme status
theme status
```
### What Gets Updated
**On WSL:**
- Neovim theme (via `~/.local/share/nvim_color_scheme`)
- Windows Terminal settings
- Windows system theme
- Windows sound scheme
**On macOS:**
- Neovim theme (via `~/.local/share/nvim_color_scheme`)
- Alacritty theme (via Nix configuration)
### Manual Configuration (macOS only)
You can also manually edit `nixos/home/danny/home.nix` and change:
```nix
isLightTheme = true; # for light theme
isLightTheme = false; # for dark theme
```
Then run: `cd nixos && sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air`
## Files
- `scripts/theme.sh` - **Main unified theme switching script**
- `scripts/switch-alacritty-theme.sh` - Alacritty-specific theme switching (used by theme.sh)
- `scripts/detect-system-theme.sh` - Detects current macOS system theme (for reference)
- `nixos/fish.nix` - Contains the `theme` fish alias
- `nixos/home/danny/home.nix` - Contains the conditional Alacritty configuration
- `bashscripts/wsl_theme.sh` - Legacy WSL script (replaced by theme.sh)
- `assets/alacritty/catppuccin-latte-colors.toml` / `catppuccin-mocha-colors.toml` — palette fragments
- `scripts/alacritty-sync-system-theme.sh` — detect macOS appearance, copy palette, refresh nvim marker
- `scripts/sync-alacritty-theme.sh` — thin wrapper (backwards compatible)
- `nixos/home/danny/home.nix``programs.alacritty` + `xdg.configFile` for palettes
- `nixos/hosts/macos.nix` — LaunchAgent + `alacritty-sync-system-theme` in `environment.systemPackages`
- `nixos/fish.nix` — optional shell-open sync on Darwin
## Theme Colors
After changing Nix config, run `darwin-rebuild switch` once (see repo `AGENTS.md`).
## Theme colors
### Catppuccin Latte (Light)
- Background: `#eff1f5` (base)
- Foreground: `#4c4f69` (text)
- Accent colors optimized for light backgrounds
### Catppuccin Mocha (Dark)
- Background: `#1e1e2e` (base)
- Foreground: `#cdd6f4` (text)
- Accent colors optimized for dark backgrounds
## Integration with NixOS
The solution uses Nix's conditional configuration in `home.nix`:
```nix
colors = let
isLightTheme = true; # Change this to switch themes
lightColors = { /* Catppuccin Latte colors */ };
darkColors = { /* Catppuccin Mocha colors */ };
in if isLightTheme then lightColors else darkColors;
```
This approach:
- ✅ Works with Spotlight/Applications folder launches
- ✅ No complex file reading or external dependencies
- ✅ Integrates cleanly with NixOS configuration
- ✅ Simple and reliable - just change a boolean and rebuild
- ✅ Easy to understand and maintain

View file

@ -0,0 +1,29 @@
# Catppuccin Latte — imported by main alacritty.toml; swapped by sync script.
[colors.primary]
background = "#eff1f5"
foreground = "#4c4f69"
[colors.cursor]
text = "#eff1f5"
cursor = "#dc8a78"
[colors.normal]
black = "#5c5f77"
red = "#d20f39"
green = "#40a02b"
yellow = "#df8e1d"
blue = "#1e40af"
magenta = "#ea76cb"
cyan = "#179299"
white = "#acb0be"
[colors.bright]
black = "#6c6f85"
red = "#d20f39"
green = "#40a02b"
yellow = "#df8e1d"
blue = "#1e40af"
magenta = "#ea76cb"
cyan = "#179299"
white = "#bcc0cc"

View file

@ -0,0 +1,29 @@
# Catppuccin Mocha — imported by main alacritty.toml; swapped by sync script.
[colors.primary]
background = "#1e1e2e"
foreground = "#cdd6f4"
[colors.cursor]
text = "#1e1e2e"
cursor = "#f5e0dc"
[colors.normal]
black = "#45475a"
red = "#f38ba8"
green = "#a6e3a1"
yellow = "#f9e2af"
blue = "#89b4fa"
magenta = "#f5c2e7"
cyan = "#94e2d5"
white = "#bac2de"
[colors.bright]
black = "#585b70"
red = "#f38ba8"
green = "#a6e3a1"
yellow = "#f9e2af"
blue = "#89b4fa"
magenta = "#f5c2e7"
cyan = "#94e2d5"
white = "#a6adc8"

View file

@ -4,28 +4,18 @@
<dict>
<key>Label</key>
<string>com.user.alacritty-theme-sync</string>
<key>ProgramArguments</key>
<array>
<string>/Users/danny/dotfiles/scripts/sync-alacritty-theme.sh</string>
<string>/bin/bash</string>
<string>/Users/danny/dotfiles/scripts/alacritty-sync-system-theme.sh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
<key>RunAtLoad</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/alacritty-theme-sync.log</string>
<key>StandardErrorPath</key>
<string>/tmp/alacritty-theme-sync-error.log</string>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
</dict>
</plist>