feat: add Alacritty light and dark themes + synchronization scripts ✨
This commit is contained in:
parent
d35b908001
commit
bd9cd434d4
9 changed files with 504 additions and 1 deletions
109
assets/alacritty/README.md
Normal file
109
assets/alacritty/README.md
Normal file
|
|
@ -0,0 +1,109 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
- `catppuccin-light.yml` - Catppuccin Latte (light) theme colors
|
||||||
|
- `catppuccin-dark.yml` - Catppuccin Mocha (dark) theme colors
|
||||||
|
- `README.md` - This documentation
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. Run the setup script:
|
||||||
|
```bash
|
||||||
|
./scripts/setup-alacritty-theme-sync.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Choose your preferred method for automatic theme switching:
|
||||||
|
|
||||||
|
### Option 1: Manual Sync
|
||||||
|
Run the sync script whenever you want to update the theme:
|
||||||
|
```bash
|
||||||
|
./scripts/sync-alacritty-theme.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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:
|
||||||
|
```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
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
## Customization
|
||||||
|
|
||||||
|
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.
|
||||||
30
assets/alacritty/catppuccin-dark.yml
Normal file
30
assets/alacritty/catppuccin-dark.yml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Catppuccin Mocha (Dark) theme for Alacritty
|
||||||
|
colors:
|
||||||
|
# Catppuccin Mocha palette
|
||||||
|
primary:
|
||||||
|
background: '0x1e1e2e' # base
|
||||||
|
foreground: '0xcdd6f4' # text
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
30
assets/alacritty/catppuccin-light.yml
Normal file
30
assets/alacritty/catppuccin-light.yml
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
# Catppuccin Latte (Light) theme for Alacritty
|
||||||
|
colors:
|
||||||
|
# Catppuccin Latte palette
|
||||||
|
primary:
|
||||||
|
background: '0xeff1f5' # base
|
||||||
|
foreground: '0x4c4f69' # text
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
31
assets/launchd/com.user.alacritty-theme-sync.plist
Normal file
31
assets/launchd/com.user.alacritty-theme-sync.plist
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<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>
|
||||||
|
</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>
|
||||||
|
|
@ -132,6 +132,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
# Alacritty terminal configuration (managed by Home Manager)
|
# Alacritty terminal configuration (managed by Home Manager)
|
||||||
|
# Note: Colors are managed by the theme sync script for dynamic switching
|
||||||
programs.alacritty = {
|
programs.alacritty = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = {
|
settings = {
|
||||||
|
|
@ -153,8 +154,8 @@
|
||||||
program = "${pkgs.fish}/bin/fish";
|
program = "${pkgs.fish}/bin/fish";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
# Default colors (Catppuccin Mocha - will be overridden by theme sync)
|
||||||
colors = {
|
colors = {
|
||||||
# Catppuccin Mocha palette
|
|
||||||
primary = { background = "0x1e1e2e"; foreground = "0xcdd6f4"; };
|
primary = { background = "0x1e1e2e"; foreground = "0xcdd6f4"; };
|
||||||
normal = {
|
normal = {
|
||||||
black = "0x45475a"; red = "0xf38ba8"; green = "0xa6e3a1"; yellow = "0xf9e2af";
|
black = "0x45475a"; red = "0xf38ba8"; green = "0xa6e3a1"; yellow = "0xf9e2af";
|
||||||
|
|
|
||||||
13
scripts/detect-system-theme.sh
Executable file
13
scripts/detect-system-theme.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Detect macOS system theme (light/dark mode)
|
||||||
|
# Returns "light" or "dark"
|
||||||
|
|
||||||
|
# Get the current appearance setting
|
||||||
|
appearance=$(defaults read -g AppleInterfaceStyle 2>/dev/null)
|
||||||
|
|
||||||
|
if [ "$appearance" = "Dark" ]; then
|
||||||
|
echo "dark"
|
||||||
|
else
|
||||||
|
echo "light"
|
||||||
|
fi
|
||||||
55
scripts/monitor-theme-changes.sh
Executable file
55
scripts/monitor-theme-changes.sh
Executable file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/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
|
||||||
104
scripts/setup-alacritty-theme-sync.sh
Executable file
104
scripts/setup-alacritty-theme-sync.sh
Executable file
|
|
@ -0,0 +1,104 @@
|
||||||
|
#!/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"
|
||||||
130
scripts/sync-alacritty-theme.sh
Executable file
130
scripts/sync-alacritty-theme.sh
Executable file
|
|
@ -0,0 +1,130 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Sync Alacritty theme with system theme
|
||||||
|
# This script detects the current system theme and updates Alacritty configuration accordingly
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Get the directory where this script is located
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
|
||||||
|
|
||||||
|
# Paths
|
||||||
|
THEME_DETECTION_SCRIPT="$SCRIPT_DIR/detect-system-theme.sh"
|
||||||
|
LIGHT_THEME="$DOTFILES_DIR/assets/alacritty/catppuccin-light.yml"
|
||||||
|
DARK_THEME="$DOTFILES_DIR/assets/alacritty/catppuccin-dark.yml"
|
||||||
|
|
||||||
|
# Alacritty config locations (try different possible locations)
|
||||||
|
ALACRITTY_CONFIG_LOCATIONS=(
|
||||||
|
"$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
|
||||||
|
if [ ! -f "$THEME_DETECTION_SCRIPT" ]; then
|
||||||
|
echo "Error: Theme detection script not found at $THEME_DETECTION_SCRIPT"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CURRENT_THEME=$("$THEME_DETECTION_SCRIPT")
|
||||||
|
echo "Current system theme: $CURRENT_THEME"
|
||||||
|
|
||||||
|
# Determine which theme file to use
|
||||||
|
if [ "$CURRENT_THEME" = "light" ]; then
|
||||||
|
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 "Error: Theme file not found at $THEME_FILE"
|
||||||
|
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