feat: introduce script for manual theme switching in Alacritty and update README for clarity ✨
This commit is contained in:
parent
d7302fd9a6
commit
c8a7e3fb34
4 changed files with 121 additions and 40 deletions
|
|
@ -1,52 +1,57 @@
|
|||
# Alacritty Theme Synchronization
|
||||
|
||||
Simple theme synchronization for Alacritty that automatically switches between Catppuccin light and dark themes based on your macOS system theme.
|
||||
Simple theme switching for Alacritty that allows you to switch between Catppuccin light and dark themes.
|
||||
|
||||
**This solution uses Nix conditional configuration - no complex scripts or wrappers needed!**
|
||||
**This solution uses Nix conditional configuration with a simple script to switch themes.**
|
||||
|
||||
## How It Works
|
||||
|
||||
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
|
||||
1. The Nix configuration has a boolean variable `isLightTheme` in `home.nix`
|
||||
2. When `isLightTheme = true` → Catppuccin Latte (light theme)
|
||||
3. When `isLightTheme = false` → Catppuccin Mocha (dark theme)
|
||||
4. A script updates this variable and rebuilds the configuration
|
||||
|
||||
## Setup
|
||||
|
||||
1. **Run the setup script:**
|
||||
```bash
|
||||
./scripts/setup-simple-theme-sync.sh
|
||||
```
|
||||
1. **The configuration is already set up!** Your Alacritty is currently using the light theme.
|
||||
|
||||
2. **Apply the theme to Alacritty:**
|
||||
2. **To switch themes, use the script:**
|
||||
```bash
|
||||
home-manager switch
|
||||
./scripts/switch-alacritty-theme.sh light # Switch to light theme
|
||||
./scripts/switch-alacritty-theme.sh dark # Switch to dark theme
|
||||
./scripts/switch-alacritty-theme.sh toggle # Toggle between themes
|
||||
./scripts/switch-alacritty-theme.sh status # Show current 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:
|
||||
### Manual Theme Switching
|
||||
```bash
|
||||
./scripts/sync-alacritty-theme.sh && home-manager switch
|
||||
# Switch to light theme
|
||||
./scripts/switch-alacritty-theme.sh light
|
||||
|
||||
# Switch to dark theme
|
||||
./scripts/switch-alacritty-theme.sh dark
|
||||
|
||||
# Toggle between themes
|
||||
./scripts/switch-alacritty-theme.sh toggle
|
||||
|
||||
# Check current theme
|
||||
./scripts/switch-alacritty-theme.sh status
|
||||
```
|
||||
|
||||
### 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
|
||||
### Manual Configuration
|
||||
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/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
|
||||
- `scripts/switch-alacritty-theme.sh` - Script to switch themes
|
||||
- `scripts/detect-system-theme.sh` - Detects current macOS system theme (for reference)
|
||||
- `nixos/home/danny/home.nix` - Contains the conditional Alacritty configuration
|
||||
|
||||
## Theme Colors
|
||||
|
|
@ -67,9 +72,7 @@ The solution uses Nix's conditional configuration in `home.nix`:
|
|||
|
||||
```nix
|
||||
colors = let
|
||||
systemThemeFile = "/Users/danny/.local/share/nvim_color_scheme";
|
||||
isLightTheme = builtins.pathExists systemThemeFile &&
|
||||
builtins.readFile systemThemeFile == "light\n";
|
||||
isLightTheme = true; # Change this to switch themes
|
||||
|
||||
lightColors = { /* Catppuccin Latte colors */ };
|
||||
darkColors = { /* Catppuccin Mocha colors */ };
|
||||
|
|
@ -78,7 +81,7 @@ in if isLightTheme then lightColors else darkColors;
|
|||
|
||||
This approach:
|
||||
- ✅ Works with Spotlight/Applications folder launches
|
||||
- ✅ No shell aliases or wrapper scripts needed
|
||||
- ✅ No complex file reading or external dependencies
|
||||
- ✅ Integrates cleanly with NixOS configuration
|
||||
- ✅ Minimal complexity - just 3 simple scripts
|
||||
- ✅ Uses the same theme file as your Neovim 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