diff --git a/assets/alacritty/README.md b/assets/alacritty/README.md index a7ab4a1..ecad539 100644 --- a/assets/alacritty/README.md +++ b/assets/alacritty/README.md @@ -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 \ No newline at end of file +- ✅ Simple and reliable - just change a boolean and rebuild +- ✅ Easy to understand and maintain \ No newline at end of file diff --git a/nixos/home/danny/home.nix b/nixos/home/danny/home.nix index 7a6c220..ebd9838 100644 --- a/nixos/home/danny/home.nix +++ b/nixos/home/danny/home.nix @@ -155,11 +155,9 @@ }; # Conditional colors based on system theme 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"; + # Set this to true for light theme, false for dark theme + # You can change this and run 'darwin-rebuild switch' to switch themes + isLightTheme = true; # Catppuccin Latte (Light) colors lightColors = { diff --git a/scripts/setup-simple-theme-sync.sh b/scripts/setup-simple-theme-sync.sh index b9ea028..820114d 100755 --- a/scripts/setup-simple-theme-sync.sh +++ b/scripts/setup-simple-theme-sync.sh @@ -18,10 +18,10 @@ echo "" echo "Setup complete!" echo "" echo "To apply the theme to Alacritty, run:" -echo " home-manager switch" +echo " cd nixos && sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air" echo "" echo "To sync themes when your system theme changes:" -echo " $SCRIPT_DIR/sync-alacritty-theme.sh && home-manager switch" +echo " $SCRIPT_DIR/sync-alacritty-theme.sh && cd nixos && sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air" echo "" echo "For automatic theme switching, you can set up a LaunchAgent or" echo "run the sync script manually when needed." diff --git a/scripts/switch-alacritty-theme.sh b/scripts/switch-alacritty-theme.sh new file mode 100755 index 0000000..e3565af --- /dev/null +++ b/scripts/switch-alacritty-theme.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# Switch Alacritty theme by updating the Nix configuration +# This script changes the isLightTheme variable in home.nix and rebuilds + +set -e + +# Get the directory where this script is located +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +DOTFILES_DIR="$(dirname "$SCRIPT_DIR")" +HOME_NIX="$DOTFILES_DIR/nixos/home/danny/home.nix" + +# Check if home.nix exists +if [ ! -f "$HOME_NIX" ]; then + echo "Error: home.nix not found at $HOME_NIX" + exit 1 +fi + +# Function to switch to light theme +switch_to_light() { + echo "Switching to light theme (Catppuccin Latte)..." + sed -i '' 's/isLightTheme = false;/isLightTheme = true;/' "$HOME_NIX" +} + +# Function to switch to dark theme +switch_to_dark() { + echo "Switching to dark theme (Catppuccin Mocha)..." + sed -i '' 's/isLightTheme = true;/isLightTheme = false;/' "$HOME_NIX" +} + +# Function to show current theme +show_current() { + if grep -q "isLightTheme = true" "$HOME_NIX"; then + echo "Current theme: Light (Catppuccin Latte)" + else + echo "Current theme: Dark (Catppuccin Mocha)" + fi +} + +# Function to rebuild the configuration +rebuild() { + echo "Rebuilding configuration..." + cd "$DOTFILES_DIR/nixos" + sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air +} + +# Main logic +case "${1:-}" in + "light") + switch_to_light + rebuild + ;; + "dark") + switch_to_dark + rebuild + ;; + "toggle") + if grep -q "isLightTheme = true" "$HOME_NIX"; then + switch_to_dark + else + switch_to_light + fi + rebuild + ;; + "status"|"current") + show_current + ;; + *) + echo "Usage: $0 {light|dark|toggle|status}" + echo "" + echo "Commands:" + echo " light - Switch to light theme (Catppuccin Latte)" + echo " dark - Switch to dark theme (Catppuccin Mocha)" + echo " toggle - Toggle between light and dark themes" + echo " status - Show current theme" + echo "" + show_current + exit 1 + ;; +esac