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,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
|
||||
|
||||
# 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
|
||||
|
||||
# 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"
|
||||
THEME_FILE="/Users/danny/.local/share/nvim_color_scheme"
|
||||
|
||||
# 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
|
||||
# Create the directory if it doesn't exist
|
||||
mkdir -p "$(dirname "$THEME_FILE")"
|
||||
|
||||
# Detect current system theme
|
||||
if [ ! -f "$THEME_DETECTION_SCRIPT" ]; then
|
||||
|
|
@ -48,83 +24,8 @@ 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
|
||||
# Write the theme to the file that Nix reads
|
||||
echo "$CURRENT_THEME" > "$THEME_FILE"
|
||||
|
||||
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
|
||||
echo "Theme file updated: $THEME_FILE"
|
||||
echo "Run 'home-manager switch' to apply the new theme to Alacritty"
|
||||
Loading…
Add table
Add a link
Reference in a new issue