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:
parent
18ccebc109
commit
b311e21d5b
15 changed files with 196 additions and 293 deletions
|
|
@ -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`. Alacritty’s `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
|
||||
Loading…
Add table
Add a link
Reference in a new issue