refactor: simplify Alacritty theme synchronization with Nix configuration and remove obsolete scripts ✨
This commit is contained in:
parent
bd9cd434d4
commit
d7302fd9a6
8 changed files with 165 additions and 401 deletions
|
|
@ -1,64 +1,53 @@
|
||||||
# Alacritty Theme Synchronization
|
# 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
|
## How It Works
|
||||||
- `catppuccin-dark.yml` - Catppuccin Mocha (dark) theme colors
|
|
||||||
- `README.md` - This documentation
|
|
||||||
|
|
||||||
## Scripts
|
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`
|
||||||
The theme synchronization scripts are located in `/scripts/`:
|
3. Your NixOS configuration reads this file and conditionally applies:
|
||||||
|
- **Light theme** → Catppuccin Latte
|
||||||
- `detect-system-theme.sh` - Detects current macOS system theme (light/dark)
|
- **Dark theme** → Catppuccin Mocha
|
||||||
- `sync-alacritty-theme.sh` - Syncs Alacritty config with current system theme
|
4. Alacritty gets the correct theme colors through Nix configuration
|
||||||
- `monitor-theme-changes.sh` - Continuously monitors for theme changes
|
|
||||||
- `setup-alacritty-theme-sync.sh` - Setup script for initial configuration
|
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. Run the setup script:
|
1. **Run the setup script:**
|
||||||
```bash
|
```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
|
That's it! Your Alacritty will now use the correct theme based on your system theme.
|
||||||
Run the sync script whenever you want to update the theme:
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
### Manual Theme Sync
|
||||||
|
When you change your system theme, run:
|
||||||
```bash
|
```bash
|
||||||
./scripts/sync-alacritty-theme.sh
|
./scripts/sync-alacritty-theme.sh && home-manager switch
|
||||||
```
|
```
|
||||||
|
|
||||||
### Option 2: Background Monitoring
|
### Automatic Theme Switching (Optional)
|
||||||
Run the monitor script in the background:
|
For automatic switching, you can set up a LaunchAgent:
|
||||||
```bash
|
|
||||||
./scripts/monitor-theme-changes.sh &
|
|
||||||
```
|
|
||||||
|
|
||||||
### Option 3: LaunchAgent (Recommended)
|
|
||||||
Install as a system service that runs automatically:
|
|
||||||
```bash
|
```bash
|
||||||
cp assets/launchd/com.user.alacritty-theme-sync.plist ~/Library/LaunchAgents/
|
cp assets/launchd/com.user.alacritty-theme-sync.plist ~/Library/LaunchAgents/
|
||||||
launchctl load ~/Library/LaunchAgents/com.user.alacritty-theme-sync.plist
|
launchctl load ~/Library/LaunchAgents/com.user.alacritty-theme-sync.plist
|
||||||
```
|
```
|
||||||
|
|
||||||
### Option 4: Shell Integration
|
## Files
|
||||||
Add to your Fish shell configuration:
|
|
||||||
```bash
|
|
||||||
echo 'source /Users/danny/dotfiles/scripts/sync-alacritty-theme.sh' >> ~/.config/fish/config.fish
|
|
||||||
```
|
|
||||||
|
|
||||||
## How It Works
|
- `scripts/detect-system-theme.sh` - Detects current macOS system theme
|
||||||
|
- `scripts/sync-alacritty-theme.sh` - Updates the theme file that Nix reads
|
||||||
1. The system detects your current macOS theme using `defaults read -g AppleInterfaceStyle`
|
- `scripts/setup-simple-theme-sync.sh` - One-time setup script
|
||||||
2. Based on the theme, it applies the appropriate Catppuccin color scheme:
|
- `nixos/home/danny/home.nix` - Contains the conditional Alacritty configuration
|
||||||
- **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
|
|
||||||
|
|
||||||
## Theme Colors
|
## Theme Colors
|
||||||
|
|
||||||
|
|
@ -72,38 +61,24 @@ echo 'source /Users/danny/dotfiles/scripts/sync-alacritty-theme.sh' >> ~/.config
|
||||||
- Foreground: `#cdd6f4` (text)
|
- Foreground: `#cdd6f4` (text)
|
||||||
- Accent colors optimized for dark backgrounds
|
- 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
|
## 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";
|
||||||
|
|
||||||
To customize the themes:
|
lightColors = { /* Catppuccin Latte colors */ };
|
||||||
|
darkColors = { /* Catppuccin Mocha colors */ };
|
||||||
|
in if isLightTheme then lightColors else darkColors;
|
||||||
|
```
|
||||||
|
|
||||||
1. Edit the color values in `catppuccin-light.yml` or `catppuccin-dark.yml`
|
This approach:
|
||||||
2. Run the sync script to apply changes
|
- ✅ Works with Spotlight/Applications folder launches
|
||||||
3. The changes will persist until the next theme switch
|
- ✅ No shell aliases or wrapper scripts needed
|
||||||
|
- ✅ Integrates cleanly with NixOS configuration
|
||||||
For more advanced customization, you can modify the sync script to use different theme files or add additional theme variants.
|
- ✅ Minimal complexity - just 3 simple scripts
|
||||||
|
- ✅ Uses the same theme file as your Neovim configuration
|
||||||
|
|
@ -1,30 +1,28 @@
|
||||||
# Catppuccin Mocha (Dark) theme for Alacritty
|
# Catppuccin Mocha (Dark) theme for Alacritty
|
||||||
colors:
|
[colors.primary]
|
||||||
# Catppuccin Mocha palette
|
background = "0x1e1e2e" # base
|
||||||
primary:
|
foreground = "0xcdd6f4" # text
|
||||||
background: '0x1e1e2e' # base
|
|
||||||
foreground: '0xcdd6f4' # text
|
|
||||||
|
|
||||||
cursor:
|
[colors.cursor]
|
||||||
text: '0x1e1e2e' # base
|
text = "0x1e1e2e" # base
|
||||||
cursor: '0xf5e0dc' # rosewater
|
cursor = "0xf5e0dc" # rosewater
|
||||||
|
|
||||||
normal:
|
[colors.normal]
|
||||||
black: '0x45475a' # surface1
|
black = "0x45475a" # surface1
|
||||||
red: '0xf38ba8' # red
|
red = "0xf38ba8" # red
|
||||||
green: '0xa6e3a1' # green
|
green = "0xa6e3a1" # green
|
||||||
yellow: '0xf9e2af' # yellow
|
yellow = "0xf9e2af" # yellow
|
||||||
blue: '0x89b4fa' # blue
|
blue = "0x89b4fa" # blue
|
||||||
magenta: '0xf5c2e7' # pink
|
magenta = "0xf5c2e7" # pink
|
||||||
cyan: '0x94e2d5' # teal
|
cyan = "0x94e2d5" # teal
|
||||||
white: '0xbac2de' # subtext1
|
white = "0xbac2de" # subtext1
|
||||||
|
|
||||||
bright:
|
[colors.bright]
|
||||||
black: '0x585b70' # surface2
|
black = "0x585b70" # surface2
|
||||||
red: '0xf38ba8' # red
|
red = "0xf38ba8" # red
|
||||||
green: '0xa6e3a1' # green
|
green = "0xa6e3a1" # green
|
||||||
yellow: '0xf9e2af' # yellow
|
yellow = "0xf9e2af" # yellow
|
||||||
blue: '0x89b4fa' # blue
|
blue = "0x89b4fa" # blue
|
||||||
magenta: '0xf5c2e7' # pink
|
magenta = "0xf5c2e7" # pink
|
||||||
cyan: '0x94e2d5' # teal
|
cyan = "0x94e2d5" # teal
|
||||||
white: '0xa6adc8' # subtext0
|
white = "0xa6adc8" # subtext0
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,28 @@
|
||||||
# Catppuccin Latte (Light) theme for Alacritty
|
# Catppuccin Latte (Light) theme for Alacritty
|
||||||
colors:
|
[colors.primary]
|
||||||
# Catppuccin Latte palette
|
background = "0xeff1f5" # base
|
||||||
primary:
|
foreground = "0x4c4f69" # text
|
||||||
background: '0xeff1f5' # base
|
|
||||||
foreground: '0x4c4f69' # text
|
|
||||||
|
|
||||||
cursor:
|
[colors.cursor]
|
||||||
text: '0xeff1f5' # base
|
text = "0xeff1f5" # base
|
||||||
cursor: '0xdc8a78' # rosewater
|
cursor = "0xdc8a78" # rosewater
|
||||||
|
|
||||||
normal:
|
[colors.normal]
|
||||||
black: '0x5c5f77' # surface1
|
black = "0x5c5f77" # surface1
|
||||||
red: '0xd20f39' # red
|
red = "0xd20f39" # red
|
||||||
green: '0x40a02b' # green
|
green = "0x40a02b" # green
|
||||||
yellow: '0xdf8e1d' # yellow
|
yellow = "0xdf8e1d" # yellow
|
||||||
blue: '0x1e40af' # blue
|
blue = "0x1e40af" # blue
|
||||||
magenta: '0xea76cb' # pink
|
magenta = "0xea76cb" # pink
|
||||||
cyan: '0x179299' # teal
|
cyan = "0x179299" # teal
|
||||||
white: '0xacb0be' # subtext1
|
white = "0xacb0be" # subtext1
|
||||||
|
|
||||||
bright:
|
[colors.bright]
|
||||||
black: '0x6c6f85' # surface2
|
black = "0x6c6f85" # surface2
|
||||||
red: '0xd20f39' # red
|
red = "0xd20f39" # red
|
||||||
green: '0x40a02b' # green
|
green = "0x40a02b" # green
|
||||||
yellow: '0xdf8e1d' # yellow
|
yellow = "0xdf8e1d" # yellow
|
||||||
blue: '0x1e40af' # blue
|
blue = "0x1e40af" # blue
|
||||||
magenta: '0xea76cb' # pink
|
magenta = "0xea76cb" # pink
|
||||||
cyan: '0x179299' # teal
|
cyan = "0x179299" # teal
|
||||||
white: '0xbcc0cc' # subtext0
|
white = "0xbcc0cc" # subtext0
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,7 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Alacritty terminal configuration (managed by Home Manager)
|
# Alacritty terminal configuration with conditional theme switching
|
||||||
# Note: Colors are managed by the theme sync script for dynamic switching
|
|
||||||
programs.alacritty = {
|
programs.alacritty = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = {
|
settings = {
|
||||||
|
|
@ -154,9 +153,32 @@
|
||||||
program = "${pkgs.fish}/bin/fish";
|
program = "${pkgs.fish}/bin/fish";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
# Default colors (Catppuccin Mocha - will be overridden by theme sync)
|
# Conditional colors based on system theme
|
||||||
colors = {
|
colors = let
|
||||||
|
# Read system theme from file (created by theme detection script)
|
||||||
|
systemThemeFile = "/Users/danny/.local/share/nvim_color_scheme";
|
||||||
|
# Default to dark theme if file doesn't exist
|
||||||
|
isLightTheme = builtins.pathExists systemThemeFile &&
|
||||||
|
builtins.readFile systemThemeFile == "light\n";
|
||||||
|
|
||||||
|
# Catppuccin Latte (Light) colors
|
||||||
|
lightColors = {
|
||||||
|
primary = { background = "0xeff1f5"; foreground = "0x4c4f69"; };
|
||||||
|
cursor = { text = "0xeff1f5"; cursor = "0xdc8a78"; };
|
||||||
|
normal = {
|
||||||
|
black = "0x5c5f77"; red = "0xd20f39"; green = "0x40a02b"; yellow = "0xdf8e1d";
|
||||||
|
blue = "0x1e40af"; magenta = "0xea76cb"; cyan = "0x179299"; white = "0xacb0be";
|
||||||
|
};
|
||||||
|
bright = {
|
||||||
|
black = "0x6c6f85"; red = "0xd20f39"; green = "0x40a02b"; yellow = "0xdf8e1d";
|
||||||
|
blue = "0x1e40af"; magenta = "0xea76cb"; cyan = "0x179299"; white = "0xbcc0cc";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# Catppuccin Mocha (Dark) colors
|
||||||
|
darkColors = {
|
||||||
primary = { background = "0x1e1e2e"; foreground = "0xcdd6f4"; };
|
primary = { background = "0x1e1e2e"; foreground = "0xcdd6f4"; };
|
||||||
|
cursor = { text = "0x1e1e2e"; cursor = "0xf5e0dc"; };
|
||||||
normal = {
|
normal = {
|
||||||
black = "0x45475a"; red = "0xf38ba8"; green = "0xa6e3a1"; yellow = "0xf9e2af";
|
black = "0x45475a"; red = "0xf38ba8"; green = "0xa6e3a1"; yellow = "0xf9e2af";
|
||||||
blue = "0x89b4fa"; magenta = "0xf5c2e7"; cyan = "0x94e2d5"; white = "0xbac2de";
|
blue = "0x89b4fa"; magenta = "0xf5c2e7"; cyan = "0x94e2d5"; white = "0xbac2de";
|
||||||
|
|
@ -166,9 +188,11 @@
|
||||||
blue = "0x89b4fa"; magenta = "0xf5c2e7"; cyan = "0x94e2d5"; white = "0xa6adc8";
|
blue = "0x89b4fa"; magenta = "0xf5c2e7"; cyan = "0x94e2d5"; white = "0xa6adc8";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
in if isLightTheme then lightColors else darkColors;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
# TODO: Put user-installed binaries here if you want HM to own them (optional)
|
# TODO: Put user-installed binaries here if you want HM to own them (optional)
|
||||||
# home.packages = with pkgs; [
|
# home.packages = with pkgs; [
|
||||||
# ];
|
# ];
|
||||||
|
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Monitor system theme changes and sync Alacritty theme
|
|
||||||
# This script runs continuously and only updates Alacritty when the theme changes
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Get the directory where this script is located
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
SYNC_SCRIPT="$SCRIPT_DIR/sync-alacritty-theme.sh"
|
|
||||||
|
|
||||||
# State file to track the last known theme
|
|
||||||
STATE_FILE="/tmp/alacritty-theme-state"
|
|
||||||
|
|
||||||
# Function to get current theme
|
|
||||||
get_current_theme() {
|
|
||||||
"$SCRIPT_DIR/detect-system-theme.sh"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to get last known theme
|
|
||||||
get_last_theme() {
|
|
||||||
if [ -f "$STATE_FILE" ]; then
|
|
||||||
cat "$STATE_FILE"
|
|
||||||
else
|
|
||||||
echo ""
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Function to save current theme
|
|
||||||
save_theme() {
|
|
||||||
echo "$1" > "$STATE_FILE"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Initial sync
|
|
||||||
echo "Starting Alacritty theme monitor..."
|
|
||||||
CURRENT_THEME=$(get_current_theme)
|
|
||||||
echo "Current theme: $CURRENT_THEME"
|
|
||||||
|
|
||||||
# Run initial sync
|
|
||||||
"$SYNC_SCRIPT"
|
|
||||||
save_theme "$CURRENT_THEME"
|
|
||||||
|
|
||||||
# Monitor for changes
|
|
||||||
while true; do
|
|
||||||
sleep 5 # Check every 5 seconds
|
|
||||||
|
|
||||||
NEW_THEME=$(get_current_theme)
|
|
||||||
LAST_THEME=$(get_last_theme)
|
|
||||||
|
|
||||||
if [ "$NEW_THEME" != "$LAST_THEME" ]; then
|
|
||||||
echo "Theme changed from '$LAST_THEME' to '$NEW_THEME'"
|
|
||||||
"$SYNC_SCRIPT"
|
|
||||||
save_theme "$NEW_THEME"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
@ -1,104 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
|
|
||||||
# Setup script for Alacritty theme synchronization
|
|
||||||
# This script installs the necessary components to sync Alacritty with system theme
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
# Get the directory where this script is located
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
||||||
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
|
|
||||||
|
|
||||||
echo "Setting up Alacritty theme synchronization..."
|
|
||||||
|
|
||||||
# Check if we're on macOS
|
|
||||||
if [[ "$OSTYPE" != "darwin"* ]]; then
|
|
||||||
echo "Error: This script is designed for macOS"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if Alacritty is installed
|
|
||||||
if ! command -v alacritty >/dev/null 2>&1; then
|
|
||||||
echo "Warning: Alacritty is not installed or not in PATH"
|
|
||||||
echo "Please install Alacritty first: brew install alacritty"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create Alacritty config directory if it doesn't exist
|
|
||||||
ALACRITTY_CONFIG_DIR="$HOME/.config/alacritty"
|
|
||||||
mkdir -p "$ALACRITTY_CONFIG_DIR"
|
|
||||||
|
|
||||||
# Check if Alacritty config exists
|
|
||||||
ALACRITTY_CONFIG="$ALACRITTY_CONFIG_DIR/alacritty.yml"
|
|
||||||
if [ ! -f "$ALACRITTY_CONFIG" ]; then
|
|
||||||
echo "Creating default Alacritty configuration..."
|
|
||||||
cat > "$ALACRITTY_CONFIG" << 'EOF'
|
|
||||||
# Alacritty configuration
|
|
||||||
# This file will be automatically updated by the theme sync script
|
|
||||||
|
|
||||||
window:
|
|
||||||
padding:
|
|
||||||
x: 8
|
|
||||||
y: 8
|
|
||||||
dynamic_padding: true
|
|
||||||
decorations: buttonless
|
|
||||||
opacity: 0.95
|
|
||||||
startup_mode: Fullscreen
|
|
||||||
option_as_alt: Both
|
|
||||||
|
|
||||||
scrolling:
|
|
||||||
history: 10000
|
|
||||||
multiplier: 3
|
|
||||||
|
|
||||||
font:
|
|
||||||
size: 13.0
|
|
||||||
|
|
||||||
cursor:
|
|
||||||
style: Block
|
|
||||||
unfocused_hollow: true
|
|
||||||
|
|
||||||
terminal:
|
|
||||||
shell:
|
|
||||||
program: /bin/fish
|
|
||||||
|
|
||||||
# Colors will be automatically managed by theme sync
|
|
||||||
colors:
|
|
||||||
primary:
|
|
||||||
background: '0x1e1e2e'
|
|
||||||
foreground: '0xcdd6f4'
|
|
||||||
EOF
|
|
||||||
echo "Created default Alacritty config at $ALACRITTY_CONFIG"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Test the theme detection script
|
|
||||||
echo "Testing theme detection..."
|
|
||||||
CURRENT_THEME=$("$SCRIPT_DIR/detect-system-theme.sh")
|
|
||||||
echo "Current system theme: $CURRENT_THEME"
|
|
||||||
|
|
||||||
# Test the sync script
|
|
||||||
echo "Testing theme synchronization..."
|
|
||||||
"$SCRIPT_DIR/sync-alacritty-theme.sh"
|
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Setup complete! Here's what was configured:"
|
|
||||||
echo ""
|
|
||||||
echo "1. Theme detection script: $SCRIPT_DIR/detect-system-theme.sh"
|
|
||||||
echo "2. Theme sync script: $SCRIPT_DIR/sync-alacritty-theme.sh"
|
|
||||||
echo "3. Theme monitor script: $SCRIPT_DIR/monitor-theme-changes.sh"
|
|
||||||
echo "4. Alacritty config: $ALACRITTY_CONFIG"
|
|
||||||
echo ""
|
|
||||||
echo "To enable automatic theme switching, you have several options:"
|
|
||||||
echo ""
|
|
||||||
echo "Option 1 - Manual sync (run when needed):"
|
|
||||||
echo " $SCRIPT_DIR/sync-alacritty-theme.sh"
|
|
||||||
echo ""
|
|
||||||
echo "Option 2 - Background monitoring (runs continuously):"
|
|
||||||
echo " $SCRIPT_DIR/monitor-theme-changes.sh &"
|
|
||||||
echo ""
|
|
||||||
echo "Option 3 - LaunchAgent (automatic startup):"
|
|
||||||
echo " cp $DOTFILES_DIR/assets/launchd/com.user.alacritty-theme-sync.plist ~/Library/LaunchAgents/"
|
|
||||||
echo " launchctl load ~/Library/LaunchAgents/com.user.alacritty-theme-sync.plist"
|
|
||||||
echo ""
|
|
||||||
echo "Option 4 - Add to shell profile (runs on terminal startup):"
|
|
||||||
echo " echo 'source $SCRIPT_DIR/sync-alacritty-theme.sh' >> ~/.config/fish/config.fish"
|
|
||||||
echo ""
|
|
||||||
echo "Current theme applied: $CURRENT_THEME"
|
|
||||||
27
scripts/setup-simple-theme-sync.sh
Executable file
27
scripts/setup-simple-theme-sync.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple setup for Alacritty theme synchronization
|
||||||
|
# This creates the theme file and rebuilds the Nix configuration
|
||||||
|
|
||||||
|
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 ""
|
||||||
|
echo "Setup complete!"
|
||||||
|
echo ""
|
||||||
|
echo "To apply the theme to Alacritty, run:"
|
||||||
|
echo " home-manager switch"
|
||||||
|
echo ""
|
||||||
|
echo "To sync themes when your system theme changes:"
|
||||||
|
echo " $SCRIPT_DIR/sync-alacritty-theme.sh && home-manager switch"
|
||||||
|
echo ""
|
||||||
|
echo "For automatic theme switching, you can set up a LaunchAgent or"
|
||||||
|
echo "run the sync script manually when needed."
|
||||||
|
|
@ -1,43 +1,19 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Sync Alacritty theme with system theme
|
# Sync Alacritty theme with system theme
|
||||||
# This script detects the current system theme and updates Alacritty configuration accordingly
|
# This script detects the current system theme and updates the theme file that Nix reads
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Get the directory where this script is located
|
# Get the directory where this script is located
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
|
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
THEME_DETECTION_SCRIPT="$SCRIPT_DIR/detect-system-theme.sh"
|
THEME_DETECTION_SCRIPT="$SCRIPT_DIR/detect-system-theme.sh"
|
||||||
LIGHT_THEME="$DOTFILES_DIR/assets/alacritty/catppuccin-light.yml"
|
THEME_FILE="/Users/danny/.local/share/nvim_color_scheme"
|
||||||
DARK_THEME="$DOTFILES_DIR/assets/alacritty/catppuccin-dark.yml"
|
|
||||||
|
|
||||||
# Alacritty config locations (try different possible locations)
|
# Create the directory if it doesn't exist
|
||||||
ALACRITTY_CONFIG_LOCATIONS=(
|
mkdir -p "$(dirname "$THEME_FILE")"
|
||||||
"$HOME/.config/alacritty/alacritty.yml"
|
|
||||||
"$HOME/.alacritty.yml"
|
|
||||||
"$HOME/Library/Application Support/Alacritty/alacritty.yml"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Find the actual Alacritty config file
|
|
||||||
ALACRITTY_CONFIG=""
|
|
||||||
for location in "${ALACRITTY_CONFIG_LOCATIONS[@]}"; do
|
|
||||||
if [ -f "$location" ]; then
|
|
||||||
ALACRITTY_CONFIG="$location"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ -z "$ALACRITTY_CONFIG" ]; then
|
|
||||||
echo "Error: Could not find Alacritty configuration file"
|
|
||||||
echo "Tried locations:"
|
|
||||||
for location in "${ALACRITTY_CONFIG_LOCATIONS[@]}"; do
|
|
||||||
echo " - $location"
|
|
||||||
done
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Detect current system theme
|
# Detect current system theme
|
||||||
if [ ! -f "$THEME_DETECTION_SCRIPT" ]; then
|
if [ ! -f "$THEME_DETECTION_SCRIPT" ]; then
|
||||||
|
|
@ -48,83 +24,8 @@ fi
|
||||||
CURRENT_THEME=$("$THEME_DETECTION_SCRIPT")
|
CURRENT_THEME=$("$THEME_DETECTION_SCRIPT")
|
||||||
echo "Current system theme: $CURRENT_THEME"
|
echo "Current system theme: $CURRENT_THEME"
|
||||||
|
|
||||||
# Determine which theme file to use
|
# Write the theme to the file that Nix reads
|
||||||
if [ "$CURRENT_THEME" = "light" ]; then
|
echo "$CURRENT_THEME" > "$THEME_FILE"
|
||||||
THEME_FILE="$LIGHT_THEME"
|
|
||||||
THEME_NAME="Catppuccin Latte (Light)"
|
|
||||||
elif [ "$CURRENT_THEME" = "dark" ]; then
|
|
||||||
THEME_FILE="$DARK_THEME"
|
|
||||||
THEME_NAME="Catppuccin Mocha (Dark)"
|
|
||||||
else
|
|
||||||
echo "Error: Unknown theme '$CURRENT_THEME'. Expected 'light' or 'dark'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -f "$THEME_FILE" ]; then
|
echo "Theme file updated: $THEME_FILE"
|
||||||
echo "Error: Theme file not found at $THEME_FILE"
|
echo "Run 'home-manager switch' to apply the new theme to Alacritty"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Applying theme: $THEME_NAME"
|
|
||||||
|
|
||||||
# Create backup of current config
|
|
||||||
BACKUP_FILE="${ALACRITTY_CONFIG}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
||||||
cp "$ALACRITTY_CONFIG" "$BACKUP_FILE"
|
|
||||||
echo "Backup created: $BACKUP_FILE"
|
|
||||||
|
|
||||||
# Create a temporary file for the new config
|
|
||||||
TEMP_CONFIG=$(mktemp)
|
|
||||||
|
|
||||||
# Function to merge theme colors into config
|
|
||||||
merge_theme() {
|
|
||||||
local config_file="$1"
|
|
||||||
local theme_file="$2"
|
|
||||||
local output_file="$3"
|
|
||||||
|
|
||||||
# Use yq to merge the theme colors into the config
|
|
||||||
# If yq is not available, fall back to a simpler approach
|
|
||||||
if command -v yq >/dev/null 2>&1; then
|
|
||||||
# Use yq for proper YAML merging
|
|
||||||
yq eval-all 'select(fileIndex == 0) * select(fileIndex == 1)' "$config_file" "$theme_file" > "$output_file"
|
|
||||||
else
|
|
||||||
# Fallback: simple approach that replaces the colors section
|
|
||||||
# This is less robust but works without yq
|
|
||||||
awk '
|
|
||||||
BEGIN { in_colors = 0; colors_printed = 0 }
|
|
||||||
/^colors:/ {
|
|
||||||
in_colors = 1
|
|
||||||
if (!colors_printed) {
|
|
||||||
print "colors:"
|
|
||||||
while ((getline line < "'"$theme_file"'") > 0) {
|
|
||||||
if (line ~ /^colors:/) continue
|
|
||||||
print " " line
|
|
||||||
}
|
|
||||||
close("'"$theme_file"'")
|
|
||||||
colors_printed = 1
|
|
||||||
}
|
|
||||||
next
|
|
||||||
}
|
|
||||||
in_colors && /^[a-zA-Z]/ && !/^ / { in_colors = 0 }
|
|
||||||
!in_colors { print }
|
|
||||||
' "$config_file" > "$output_file"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Merge the theme into the config
|
|
||||||
merge_theme "$ALACRITTY_CONFIG" "$THEME_FILE" "$TEMP_CONFIG"
|
|
||||||
|
|
||||||
# Replace the original config with the new one
|
|
||||||
mv "$TEMP_CONFIG" "$ALACRITTY_CONFIG"
|
|
||||||
|
|
||||||
echo "Alacritty theme synchronized successfully!"
|
|
||||||
echo "Config file: $ALACRITTY_CONFIG"
|
|
||||||
echo "Applied theme: $THEME_NAME"
|
|
||||||
|
|
||||||
# Optionally, send a signal to running Alacritty instances to reload config
|
|
||||||
# This requires Alacritty to be running with live config reload enabled
|
|
||||||
if command -v osascript >/dev/null 2>&1; then
|
|
||||||
# Try to reload Alacritty config using AppleScript
|
|
||||||
osascript -e 'tell application "Alacritty" to quit' 2>/dev/null || true
|
|
||||||
# Restart Alacritty (you might want to adjust this based on your setup)
|
|
||||||
open -a Alacritty 2>/dev/null || true
|
|
||||||
fi
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue