refactor: simplify Alacritty theme synchronization with Nix configuration and remove obsolete scripts

This commit is contained in:
DannyDannyDanny 2025-09-12 13:13:31 +02:00
parent bd9cd434d4
commit d7302fd9a6
8 changed files with 165 additions and 401 deletions

View file

@ -1,64 +1,53 @@
# Alacritty Theme Synchronization
This directory contains the theme synchronization system for Alacritty that automatically switches between Catppuccin light and dark themes based on your macOS system theme.
Simple theme synchronization for Alacritty that automatically switches between Catppuccin light and dark themes based on your macOS system theme.
## Files
**This solution uses Nix conditional configuration - no complex scripts or wrappers needed!**
- `catppuccin-light.yml` - Catppuccin Latte (light) theme colors
- `catppuccin-dark.yml` - Catppuccin Mocha (dark) theme colors
- `README.md` - This documentation
## How It Works
## Scripts
The theme synchronization scripts are located in `/scripts/`:
- `detect-system-theme.sh` - Detects current macOS system theme (light/dark)
- `sync-alacritty-theme.sh` - Syncs Alacritty config with current system theme
- `monitor-theme-changes.sh` - Continuously monitors for theme changes
- `setup-alacritty-theme-sync.sh` - Setup script for initial configuration
1. The system detects your current macOS theme using `defaults read -g AppleInterfaceStyle`
2. The theme is written to `/Users/danny/.local/share/nvim_color_scheme`
3. Your NixOS configuration reads this file and conditionally applies:
- **Light theme** → Catppuccin Latte
- **Dark theme** → Catppuccin Mocha
4. Alacritty gets the correct theme colors through Nix configuration
## Setup
1. Run the setup script:
1. **Run the setup script:**
```bash
./scripts/setup-alacritty-theme-sync.sh
./scripts/setup-simple-theme-sync.sh
```
2. Choose your preferred method for automatic theme switching:
2. **Apply the theme to Alacritty:**
```bash
home-manager switch
```
### Option 1: Manual Sync
Run the sync script whenever you want to update the theme:
That's it! Your Alacritty will now use the correct theme based on your system theme.
## Usage
### Manual Theme Sync
When you change your system theme, run:
```bash
./scripts/sync-alacritty-theme.sh
./scripts/sync-alacritty-theme.sh && home-manager switch
```
### Option 2: Background Monitoring
Run the monitor script in the background:
```bash
./scripts/monitor-theme-changes.sh &
```
### Option 3: LaunchAgent (Recommended)
Install as a system service that runs automatically:
### Automatic Theme Switching (Optional)
For automatic switching, you can set up a LaunchAgent:
```bash
cp assets/launchd/com.user.alacritty-theme-sync.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.user.alacritty-theme-sync.plist
```
### Option 4: Shell Integration
Add to your Fish shell configuration:
```bash
echo 'source /Users/danny/dotfiles/scripts/sync-alacritty-theme.sh' >> ~/.config/fish/config.fish
```
## Files
## How It Works
1. The system detects your current macOS theme using `defaults read -g AppleInterfaceStyle`
2. Based on the theme, it applies the appropriate Catppuccin color scheme:
- **Light theme** → Catppuccin Latte
- **Dark theme** → Catppuccin Mocha
3. The Alacritty configuration is updated with the new colors
4. Running Alacritty instances are restarted to apply the new theme
- `scripts/detect-system-theme.sh` - Detects current macOS system theme
- `scripts/sync-alacritty-theme.sh` - Updates the theme file that Nix reads
- `scripts/setup-simple-theme-sync.sh` - One-time setup script
- `nixos/home/danny/home.nix` - Contains the conditional Alacritty configuration
## Theme Colors
@ -72,38 +61,24 @@ echo 'source /Users/danny/dotfiles/scripts/sync-alacritty-theme.sh' >> ~/.config
- Foreground: `#cdd6f4` (text)
- Accent colors optimized for dark backgrounds
## Troubleshooting
### Theme not updating
- Check if Alacritty config file exists and is writable
- Verify the theme detection script works: `./scripts/detect-system-theme.sh`
- Check logs in `/tmp/alacritty-theme-sync.log`
### LaunchAgent not working
- Check if the plist file is in the correct location
- Verify permissions: `ls -la ~/Library/LaunchAgents/`
- Check launchctl status: `launchctl list | grep alacritty`
### Manual theme override
If you want to manually set a theme regardless of system setting:
```bash
# Force light theme
ALACRITTY_THEME=light ./scripts/sync-alacritty-theme.sh
# Force dark theme
ALACRITTY_THEME=dark ./scripts/sync-alacritty-theme.sh
```
## Integration with NixOS
The NixOS configuration in `nixos/home/danny/home.nix` provides the base Alacritty configuration. The theme sync scripts work on top of this configuration, dynamically updating the colors section while preserving all other settings.
The solution uses Nix's conditional configuration in `home.nix`:
## Customization
```nix
colors = let
systemThemeFile = "/Users/danny/.local/share/nvim_color_scheme";
isLightTheme = builtins.pathExists systemThemeFile &&
builtins.readFile systemThemeFile == "light\n";
lightColors = { /* Catppuccin Latte colors */ };
darkColors = { /* Catppuccin Mocha colors */ };
in if isLightTheme then lightColors else darkColors;
```
To customize the themes:
1. Edit the color values in `catppuccin-light.yml` or `catppuccin-dark.yml`
2. Run the sync script to apply changes
3. The changes will persist until the next theme switch
For more advanced customization, you can modify the sync script to use different theme files or add additional theme variants.
This approach:
- ✅ Works with Spotlight/Applications folder launches
- ✅ No shell aliases or wrapper scripts needed
- ✅ Integrates cleanly with NixOS configuration
- ✅ Minimal complexity - just 3 simple scripts
- ✅ Uses the same theme file as your Neovim configuration

View file

@ -1,30 +1,28 @@
# Catppuccin Mocha (Dark) theme for Alacritty
colors:
# Catppuccin Mocha palette
primary:
background: '0x1e1e2e' # base
foreground: '0xcdd6f4' # text
[colors.primary]
background = "0x1e1e2e" # base
foreground = "0xcdd6f4" # text
cursor:
text: '0x1e1e2e' # base
cursor: '0xf5e0dc' # rosewater
[colors.cursor]
text = "0x1e1e2e" # base
cursor = "0xf5e0dc" # rosewater
normal:
black: '0x45475a' # surface1
red: '0xf38ba8' # red
green: '0xa6e3a1' # green
yellow: '0xf9e2af' # yellow
blue: '0x89b4fa' # blue
magenta: '0xf5c2e7' # pink
cyan: '0x94e2d5' # teal
white: '0xbac2de' # subtext1
[colors.normal]
black = "0x45475a" # surface1
red = "0xf38ba8" # red
green = "0xa6e3a1" # green
yellow = "0xf9e2af" # yellow
blue = "0x89b4fa" # blue
magenta = "0xf5c2e7" # pink
cyan = "0x94e2d5" # teal
white = "0xbac2de" # subtext1
bright:
black: '0x585b70' # surface2
red: '0xf38ba8' # red
green: '0xa6e3a1' # green
yellow: '0xf9e2af' # yellow
blue: '0x89b4fa' # blue
magenta: '0xf5c2e7' # pink
cyan: '0x94e2d5' # teal
white: '0xa6adc8' # subtext0
[colors.bright]
black = "0x585b70" # surface2
red = "0xf38ba8" # red
green = "0xa6e3a1" # green
yellow = "0xf9e2af" # yellow
blue = "0x89b4fa" # blue
magenta = "0xf5c2e7" # pink
cyan = "0x94e2d5" # teal
white = "0xa6adc8" # subtext0

View file

@ -1,30 +1,28 @@
# Catppuccin Latte (Light) theme for Alacritty
colors:
# Catppuccin Latte palette
primary:
background: '0xeff1f5' # base
foreground: '0x4c4f69' # text
[colors.primary]
background = "0xeff1f5" # base
foreground = "0x4c4f69" # text
cursor:
text: '0xeff1f5' # base
cursor: '0xdc8a78' # rosewater
[colors.cursor]
text = "0xeff1f5" # base
cursor = "0xdc8a78" # rosewater
normal:
black: '0x5c5f77' # surface1
red: '0xd20f39' # red
green: '0x40a02b' # green
yellow: '0xdf8e1d' # yellow
blue: '0x1e40af' # blue
magenta: '0xea76cb' # pink
cyan: '0x179299' # teal
white: '0xacb0be' # subtext1
[colors.normal]
black = "0x5c5f77" # surface1
red = "0xd20f39" # red
green = "0x40a02b" # green
yellow = "0xdf8e1d" # yellow
blue = "0x1e40af" # blue
magenta = "0xea76cb" # pink
cyan = "0x179299" # teal
white = "0xacb0be" # subtext1
bright:
black: '0x6c6f85' # surface2
red: '0xd20f39' # red
green: '0x40a02b' # green
yellow: '0xdf8e1d' # yellow
blue: '0x1e40af' # blue
magenta: '0xea76cb' # pink
cyan: '0x179299' # teal
white: '0xbcc0cc' # subtext0
[colors.bright]
black = "0x6c6f85" # surface2
red = "0xd20f39" # red
green = "0x40a02b" # green
yellow = "0xdf8e1d" # yellow
blue = "0x1e40af" # blue
magenta = "0xea76cb" # pink
cyan = "0x179299" # teal
white = "0xbcc0cc" # subtext0