From b311e21d5b488e62e993e40a11bfc09f8228f4c0 Mon Sep 17 00:00:00 2001 From: DannyDannyDanny Date: Mon, 23 Mar 2026 19:16:05 +0100 Subject: [PATCH] feat(macos): Alacritty follows system light/dark appearance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New setup — due for review after you run darwin-rebuild switch and live with it for a few days. See CLAUDE.md (Alacritty) and assets/alacritty/README.md. - HM: import active-colors.toml + Catppuccin latte/mocha fragments - nix-darwin: launchd.user.agents.alacritty-system-theme + PATH helper - fish: background sync on Darwin; theme.sh no longer rebuilds for Alacritty - Remove switch-alacritty-theme.sh (sed + darwin-rebuild per toggle) Made-with: Cursor --- CLAUDE.md | 4 + assets/alacritty/README.md | 106 +++++------------- ...tppuccin-dark.yml => catppuccin-dark.toml} | 0 assets/alacritty/catppuccin-latte-colors.toml | 29 +++++ ...puccin-light.yml => catppuccin-light.toml} | 0 assets/alacritty/catppuccin-mocha-colors.toml | 29 +++++ .../com.user.alacritty-theme-sync.plist | 14 +-- nixos/fish.nix | 5 + nixos/home/danny/home.nix | 61 ++++------ nixos/hosts/macos.nix | 18 ++- scripts/alacritty-sync-system-theme.sh | 40 +++++++ scripts/setup-simple-theme-sync.sh | 28 +---- scripts/switch-alacritty-theme.sh | 80 ------------- scripts/sync-alacritty-theme.sh | 30 +---- scripts/theme.sh | 45 ++------ 15 files changed, 196 insertions(+), 293 deletions(-) rename assets/alacritty/{catppuccin-dark.yml => catppuccin-dark.toml} (100%) create mode 100644 assets/alacritty/catppuccin-latte-colors.toml rename assets/alacritty/{catppuccin-light.yml => catppuccin-light.toml} (100%) create mode 100644 assets/alacritty/catppuccin-mocha-colors.toml create mode 100644 scripts/alacritty-sync-system-theme.sh delete mode 100755 scripts/switch-alacritty-theme.sh diff --git a/CLAUDE.md b/CLAUDE.md index c7544c0..a433568 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -54,6 +54,10 @@ cd ~/dotfiles/nixos && nix build .#installer-iso Custom nix-darwin module at `nixos/ollama.nix` (upstream PR not yet merged). Enabled on macOS via `nixos/hosts/macos.nix`. Runs as a launchd user agent with `ollama serve`. +## Alacritty (macOS) + +Terminal colors follow **System Settings → Appearance**: `programs.alacritty` imports `~/.config/alacritty/active-colors.toml`; `scripts/alacritty-sync-system-theme.sh` copies Catppuccin latte/mocha there when the OS mode changes. **nix-darwin** `launchd.user.agents.alacritty-system-theme` polls every 30s; **fish** runs the same script on interactive startup. After changing Nix, one `darwin-rebuild switch`. Details: `assets/alacritty/README.md`. + ## Shell Fish is the default shell. Bash auto-execs fish unless the parent process is already fish. Vi keybindings with fzf integration. Zoxide aliased to `cd`. diff --git a/assets/alacritty/README.md b/assets/alacritty/README.md index f590549..0ac58d4 100644 --- a/assets/alacritty/README.md +++ b/assets/alacritty/README.md @@ -1,102 +1,54 @@ -# Unified Theme Switching +# Alacritty + system appearance (macOS) -Unified theme switching that works across platforms (WSL and macOS) for Neovim, Alacritty, and Windows Terminal. +Alacritty follows **System Settings → Appearance** automatically. No `darwin-rebuild` when you change light/dark. -**This solution uses a single `theme` command that detects the platform and switches themes appropriately.** +## How it works -## How It Works +1. Home Manager installs Catppuccin palettes as `~/.config/alacritty/catppuccin-{latte,mocha}-colors.toml` and a generated `alacritty.toml` that sets `general.import` to `active-colors.toml`. +2. `scripts/alacritty-sync-system-theme.sh` copies the matching palette to `active-colors.toml`. Alacritty’s `live_config_reload` picks it up immediately. +3. **nix-darwin** runs that script from a user LaunchAgent every 30s (`nixos/hosts/macos.nix`: `launchd.user.agents.alacritty-system-theme`). It is also installed on `PATH` as `alacritty-sync-system-theme`. +4. **Fish** runs the same script in the background when you open an interactive shell on Darwin, so changes apply quickly without waiting for the next poll. -1. The `theme` command detects the platform (WSL vs macOS) -2. **On WSL:** Updates Neovim, Windows Terminal, and Windows system theme -3. **On macOS:** Updates Neovim and Alacritty themes via Nix configuration -4. Uses the same `nvim_color_scheme` file for Neovim on both platforms +## Optional manual LaunchAgent -## Setup +If you are not using the nix-darwin agent, you can load `assets/launchd/com.user.alacritty-theme-sync.plist` (adjust paths if needed). **Do not** load both the nix-darwin agent and this plist or you will run two pollers. -1. **The configuration is already set up!** The `theme` command is available as a fish alias. +If you previously used the old plist label `com.user.alacritty-theme-sync` and switch to nix-darwin only: -2. **To switch themes, use the unified command:** - ```bash - theme light # Switch to light theme - theme dark # Switch to dark theme - theme toggle # Toggle between light and dark themes - theme status # Show current theme status - ``` - -## Usage - -### Unified Theme Command ```bash -# Switch to light theme (works on WSL and macOS) -theme light +launchctl bootout "gui/$(id -u)" ~/Library/LaunchAgents/com.user.alacritty-theme-sync.plist 2>/dev/null || true +``` -# Switch to dark theme (works on WSL and macOS) +## `theme` command (Neovim / WSL) + +The fish alias `theme` still updates `~/.local/share/nvim_color_scheme` (and Windows Terminal on WSL). On macOS, **Alacritty ignores** `theme light|dark` for terminal colors—it only follows System Settings. Neovim stays on whatever you set with `theme`; the Alacritty sync script does not touch the nvim file. + +```bash +theme light # Neovim (+ WSL terminal); macOS Alacritty unchanged (uses Appearance) theme dark - -# Toggle between light and dark themes theme toggle - -# Show current theme status theme status ``` -### What Gets Updated - -**On WSL:** -- Neovim theme (via `~/.local/share/nvim_color_scheme`) -- Windows Terminal settings -- Windows system theme -- Windows sound scheme - -**On macOS:** -- Neovim theme (via `~/.local/share/nvim_color_scheme`) -- Alacritty theme (via Nix configuration) - -### Manual Configuration (macOS only) -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/theme.sh` - **Main unified theme switching script** -- `scripts/switch-alacritty-theme.sh` - Alacritty-specific theme switching (used by theme.sh) -- `scripts/detect-system-theme.sh` - Detects current macOS system theme (for reference) -- `nixos/fish.nix` - Contains the `theme` fish alias -- `nixos/home/danny/home.nix` - Contains the conditional Alacritty configuration -- `bashscripts/wsl_theme.sh` - Legacy WSL script (replaced by theme.sh) +- `assets/alacritty/catppuccin-latte-colors.toml` / `catppuccin-mocha-colors.toml` — palette fragments +- `scripts/alacritty-sync-system-theme.sh` — detect macOS appearance, copy palette, refresh nvim marker +- `scripts/sync-alacritty-theme.sh` — thin wrapper (backwards compatible) +- `nixos/home/danny/home.nix` — `programs.alacritty` + `xdg.configFile` for palettes +- `nixos/hosts/macos.nix` — LaunchAgent + `alacritty-sync-system-theme` in `environment.systemPackages` +- `nixos/fish.nix` — optional shell-open sync on Darwin -## Theme Colors +After changing Nix config, run `darwin-rebuild switch` once (see repo `AGENTS.md`). + +## 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 - -## Integration with NixOS - -The solution uses Nix's conditional configuration in `home.nix`: - -```nix -colors = let - isLightTheme = true; # Change this to switch themes - - lightColors = { /* Catppuccin Latte colors */ }; - darkColors = { /* Catppuccin Mocha colors */ }; -in if isLightTheme then lightColors else darkColors; -``` - -This approach: -- ✅ Works with Spotlight/Applications folder launches -- ✅ No complex file reading or external dependencies -- ✅ Integrates cleanly with NixOS configuration -- ✅ Simple and reliable - just change a boolean and rebuild -- ✅ Easy to understand and maintain \ No newline at end of file diff --git a/assets/alacritty/catppuccin-dark.yml b/assets/alacritty/catppuccin-dark.toml similarity index 100% rename from assets/alacritty/catppuccin-dark.yml rename to assets/alacritty/catppuccin-dark.toml diff --git a/assets/alacritty/catppuccin-latte-colors.toml b/assets/alacritty/catppuccin-latte-colors.toml new file mode 100644 index 0000000..dbc54cd --- /dev/null +++ b/assets/alacritty/catppuccin-latte-colors.toml @@ -0,0 +1,29 @@ +# Catppuccin Latte — imported by main alacritty.toml; swapped by sync script. + +[colors.primary] +background = "#eff1f5" +foreground = "#4c4f69" + +[colors.cursor] +text = "#eff1f5" +cursor = "#dc8a78" + +[colors.normal] +black = "#5c5f77" +red = "#d20f39" +green = "#40a02b" +yellow = "#df8e1d" +blue = "#1e40af" +magenta = "#ea76cb" +cyan = "#179299" +white = "#acb0be" + +[colors.bright] +black = "#6c6f85" +red = "#d20f39" +green = "#40a02b" +yellow = "#df8e1d" +blue = "#1e40af" +magenta = "#ea76cb" +cyan = "#179299" +white = "#bcc0cc" diff --git a/assets/alacritty/catppuccin-light.yml b/assets/alacritty/catppuccin-light.toml similarity index 100% rename from assets/alacritty/catppuccin-light.yml rename to assets/alacritty/catppuccin-light.toml diff --git a/assets/alacritty/catppuccin-mocha-colors.toml b/assets/alacritty/catppuccin-mocha-colors.toml new file mode 100644 index 0000000..866f246 --- /dev/null +++ b/assets/alacritty/catppuccin-mocha-colors.toml @@ -0,0 +1,29 @@ +# Catppuccin Mocha — imported by main alacritty.toml; swapped by sync script. + +[colors.primary] +background = "#1e1e2e" +foreground = "#cdd6f4" + +[colors.cursor] +text = "#1e1e2e" +cursor = "#f5e0dc" + +[colors.normal] +black = "#45475a" +red = "#f38ba8" +green = "#a6e3a1" +yellow = "#f9e2af" +blue = "#89b4fa" +magenta = "#f5c2e7" +cyan = "#94e2d5" +white = "#bac2de" + +[colors.bright] +black = "#585b70" +red = "#f38ba8" +green = "#a6e3a1" +yellow = "#f9e2af" +blue = "#89b4fa" +magenta = "#f5c2e7" +cyan = "#94e2d5" +white = "#a6adc8" diff --git a/assets/launchd/com.user.alacritty-theme-sync.plist b/assets/launchd/com.user.alacritty-theme-sync.plist index c23206d..02a25da 100644 --- a/assets/launchd/com.user.alacritty-theme-sync.plist +++ b/assets/launchd/com.user.alacritty-theme-sync.plist @@ -4,28 +4,18 @@ Label com.user.alacritty-theme-sync - ProgramArguments - /Users/danny/dotfiles/scripts/sync-alacritty-theme.sh + /bin/bash + /Users/danny/dotfiles/scripts/alacritty-sync-system-theme.sh - StartInterval 30 - RunAtLoad - StandardOutPath /tmp/alacritty-theme-sync.log - StandardErrorPath /tmp/alacritty-theme-sync-error.log - - EnvironmentVariables - - PATH - /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin - diff --git a/nixos/fish.nix b/nixos/fish.nix index 5c7a2d2..c32edaa 100644 --- a/nixos/fish.nix +++ b/nixos/fish.nix @@ -24,6 +24,11 @@ set fish_greeting 🐟: (set_color yellow; date +%T; set_color green; date --iso-8601 2>/dev/null; or date +%F; set_color normal) + # Alacritty palette follows macOS appearance; refresh when opening a shell (LaunchAgent also polls). + if test (uname -s) = Darwin + bash ~/dotfiles/scripts/alacritty-sync-system-theme.sh >/dev/null 2>&1 & + end + # name: Default # author: Lily Ballard # edits: DannyDannyDanny diff --git a/nixos/home/danny/home.nix b/nixos/home/danny/home.nix index ce08a80..f2b4384 100644 --- a/nixos/home/danny/home.nix +++ b/nixos/home/danny/home.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, zen-browser ? null, ... }: +{ pkgs, lib, config, zen-browser ? null, ... }: { # TODO: remove next two lines from here or from flake.nix # home.username = "danny"; @@ -112,15 +112,26 @@ executable = true; }; - # Alacritty terminal configuration with conditional theme switching + # Palette fragments: synced to system appearance (see scripts/alacritty-sync-system-theme.sh). + xdg.configFile."alacritty/catppuccin-latte-colors.toml".source = + ../../../assets/alacritty/catppuccin-latte-colors.toml; + xdg.configFile."alacritty/catppuccin-mocha-colors.toml".source = + ../../../assets/alacritty/catppuccin-mocha-colors.toml; + + # Alacritty: base config + imported active-colors.toml (updated without rebuild) programs.alacritty = { enable = true; settings = { + general = { + live_config_reload = true; + import = [ "${config.xdg.configHome}/alacritty/active-colors.toml" ]; + }; window = { padding = { x = 8; y = 8; }; dynamic_padding = true; decorations = "buttonless"; - opacity = 0.95; + decorations_theme_variant = "None"; + opacity = 1.0; startup_mode = "Maximized"; option_as_alt = "Both"; }; @@ -134,43 +145,19 @@ program = "${pkgs.fish}/bin/fish"; }; }; - # Conditional colors based on system theme - colors = let - # 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 = { - 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"; }; - cursor = { text = "0x1e1e2e"; cursor = "0xf5e0dc"; }; - normal = { - black = "0x45475a"; red = "0xf38ba8"; green = "0xa6e3a1"; yellow = "0xf9e2af"; - blue = "0x89b4fa"; magenta = "0xf5c2e7"; cyan = "0x94e2d5"; white = "0xbac2de"; - }; - bright = { - black = "0x585b70"; red = "0xf38ba8"; green = "0xa6e3a1"; yellow = "0xf9e2af"; - blue = "0x89b4fa"; magenta = "0xf5c2e7"; cyan = "0x94e2d5"; white = "0xa6adc8"; - }; - }; - in if isLightTheme then lightColors else darkColors; }; }; + # Writable copy (not a symlink to the store — cp in the sync script must replace a real file). + home.activation.alacrittySystemTheme = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + MOCHA="${config.xdg.configHome}/alacritty/catppuccin-mocha-colors.toml" + ACTIVE="${config.xdg.configHome}/alacritty/active-colors.toml" + if [ ! -f "$ACTIVE" ]; then + $DRY_RUN_CMD cp "$MOCHA" "$ACTIVE" + fi + $DRY_RUN_CMD ${pkgs.bash}/bin/bash "${../../../scripts/alacritty-sync-system-theme.sh}" || true + ''; + # TODO: Put user-installed binaries here if you want HM to own them (optional) # Fonts diff --git a/nixos/hosts/macos.nix b/nixos/hosts/macos.nix index 808a61f..2061f93 100644 --- a/nixos/hosts/macos.nix +++ b/nixos/hosts/macos.nix @@ -1,6 +1,9 @@ { config, lib, pkgs, ... }: -{ +let + alacrittySyncSystemTheme = pkgs.writeShellScriptBin "alacritty-sync-system-theme" + (builtins.readFile ../../scripts/alacritty-sync-system-theme.sh); +in { # Apple Silicon + nix-darwin basics nixpkgs.hostPlatform = "aarch64-darwin"; nix.enable = false; # Determinate manages Nix @@ -48,6 +51,19 @@ # User-specific packages and environment variables are now in home-manager (home.nix) # Only system-level packages should remain here if needed + environment.systemPackages = [ alacrittySyncSystemTheme ]; + + # Poll macOS appearance; updates ~/.config/alacritty/active-colors.toml (Alacritty live_config_reload). + launchd.user.agents.alacritty-system-theme = { + serviceConfig = { + RunAtLoad = true; + StartInterval = 30; + ProgramArguments = [ "${alacrittySyncSystemTheme}/bin/alacritty-sync-system-theme" ]; + StandardOutPath = "/tmp/alacritty-theme-sync.log"; + StandardErrorPath = "/tmp/alacritty-theme-sync-error.log"; + }; + }; + # Keep for darwin as well (tracks defaults across upgrades) # current max per nix-darwin; bump only if a release notes says so system.stateVersion = 6; diff --git a/scripts/alacritty-sync-system-theme.sh b/scripts/alacritty-sync-system-theme.sh new file mode 100644 index 0000000..5e03a94 --- /dev/null +++ b/scripts/alacritty-sync-system-theme.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +# Keep Alacritty in sync with macOS light/dark appearance. +# No Nix rebuild: copies a palette into active-colors.toml; Alacritty reloads via live_config_reload. + +set -euo pipefail + +[[ "$(uname -s)" == "Darwin" ]] || exit 0 + +XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" +ALACRITTY_DIR="$XDG_CONFIG_HOME/alacritty" +ACTIVE="$ALACRITTY_DIR/active-colors.toml" +MARKER="$ALACRITTY_DIR/.last-system-theme" + +LIGHT="$ALACRITTY_DIR/catppuccin-latte-colors.toml" +DARK="$ALACRITTY_DIR/catppuccin-mocha-colors.toml" + +if [[ ! -f "$LIGHT" || ! -f "$DARK" ]]; then + echo "alacritty-sync-system-theme: missing $LIGHT or $DARK (run home-manager switch first)" >&2 + exit 1 +fi + +appearance="$(defaults read -g AppleInterfaceStyle 2>/dev/null || true)" +if [[ "$appearance" == "Dark" ]]; then + want="dark" +else + want="light" +fi + +if [[ -f "$MARKER" ]] && [[ "$(tr -d '\n' <"$MARKER")" == "$want" ]]; then + exit 0 +fi + +mkdir -p "$ALACRITTY_DIR" +printf '%s' "$want" >"$MARKER" + +if [[ "$want" == "light" ]]; then + cp "$LIGHT" "$ACTIVE" +else + cp "$DARK" "$ACTIVE" +fi diff --git a/scripts/setup-simple-theme-sync.sh b/scripts/setup-simple-theme-sync.sh index 820114d..733c9df 100755 --- a/scripts/setup-simple-theme-sync.sh +++ b/scripts/setup-simple-theme-sync.sh @@ -1,27 +1,9 @@ #!/bin/bash - -# Simple setup for Alacritty theme synchronization -# This creates the theme file and rebuilds the Nix configuration - +# One-shot sync of Alacritty palette + nvim marker from current macOS appearance. 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 "Syncing from system appearance..." +"$SCRIPT_DIR/alacritty-sync-system-theme.sh" echo "" -echo "Setup complete!" -echo "" -echo "To apply the theme to Alacritty, run:" -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 && 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." +echo "Done. Alacritty reloads colors automatically if live_config_reload is enabled." +echo "A LaunchAgent (nix-darwin: launchd.user.agents.alacritty-system-theme) runs this every 30s." diff --git a/scripts/switch-alacritty-theme.sh b/scripts/switch-alacritty-theme.sh deleted file mode 100755 index e3565af..0000000 --- a/scripts/switch-alacritty-theme.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/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 diff --git a/scripts/sync-alacritty-theme.sh b/scripts/sync-alacritty-theme.sh index e2b1b36..772536b 100755 --- a/scripts/sync-alacritty-theme.sh +++ b/scripts/sync-alacritty-theme.sh @@ -1,31 +1,5 @@ #!/bin/bash - -# Sync Alacritty theme with system theme -# This script detects the current system theme and updates the theme file that Nix reads - +# Back-compat wrapper: sync Alacritty + nvim marker from macOS appearance. set -e - -# Get the directory where this script is located SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - -# Paths -THEME_DETECTION_SCRIPT="$SCRIPT_DIR/detect-system-theme.sh" -THEME_FILE="/Users/danny/.local/share/nvim_color_scheme" - -# Create the directory if it doesn't exist -mkdir -p "$(dirname "$THEME_FILE")" - -# 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" - -# Write the theme to the file that Nix reads -echo "$CURRENT_THEME" > "$THEME_FILE" - -echo "Theme file updated: $THEME_FILE" -echo "Run 'home-manager switch' to apply the new theme to Alacritty" \ No newline at end of file +exec "$SCRIPT_DIR/alacritty-sync-system-theme.sh" diff --git a/scripts/theme.sh b/scripts/theme.sh index f0a3e1d..4cad1e4 100755 --- a/scripts/theme.sh +++ b/scripts/theme.sh @@ -17,7 +17,7 @@ show_usage() { echo "" echo "This command switches themes for:" echo " - Neovim (via nvim_color_scheme file)" - echo " - Alacritty (via Nix configuration on macOS)" + echo " - Alacritty on macOS follows System Settings (LaunchAgent sync)" echo " - Windows Terminal (via settings.json on WSL)" echo " - Windows system theme (on WSL)" } @@ -43,19 +43,11 @@ show_status() { elif [[ "$OSTYPE" == "darwin"* ]]; then echo " Platform: macOS" - # Check Alacritty theme from Nix config - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - DOTFILES_DIR="$(dirname "$SCRIPT_DIR")" - HOME_NIX="$DOTFILES_DIR/nixos/home/danny/home.nix" - - if [ -f "$HOME_NIX" ]; then - if grep -q "isLightTheme = true" "$HOME_NIX"; then - echo " Alacritty: light (Catppuccin Latte)" - else - echo " Alacritty: dark (Catppuccin Mocha)" - fi + marker="$HOME/.config/alacritty/.last-system-theme" + if [ -f "$marker" ]; then + echo " Alacritty: follows system (active palette: $(tr -d '\n' <"$marker"))" else - echo " Alacritty: config file not found" + echo " Alacritty: follows system (sync after next login or run alacritty-sync-system-theme)" fi else echo " Platform: other" @@ -67,17 +59,10 @@ toggle_theme() { current_theme="" if [[ "$OSTYPE" == "darwin"* ]]; then - # On macOS, check the Nix config for current theme - SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" - DOTFILES_DIR="$(dirname "$SCRIPT_DIR")" - HOME_NIX="$DOTFILES_DIR/nixos/home/danny/home.nix" - - if [ -f "$HOME_NIX" ]; then - if grep -q "isLightTheme = true" "$HOME_NIX"; then - current_theme="light" - else - current_theme="dark" - fi + if [[ "$(defaults read -g AppleInterfaceStyle 2>/dev/null)" == "Dark" ]]; then + current_theme="dark" + else + current_theme="light" fi fi @@ -183,18 +168,8 @@ if [[ -n "$WSL_DISTRO_NAME" ]]; then powershell.exe -Command "Set-ItemProperty -Path HKCU:\AppEvents\Schemes -Name '(Default)' -Value '.None'" elif [[ "$OSTYPE" == "darwin"* ]]; then - # macOS platform - handle Alacritty theme echo "Detected macOS platform" - - # Use the existing Alacritty theme switching script - alacritty_script="$DOTFILES_DIR/scripts/switch-alacritty-theme.sh" - if [ -f "$alacritty_script" ]; then - echo "Switching Alacritty theme to: $color_scheme" - "$alacritty_script" "$color_scheme" - else - echo "Warning: Alacritty theme script not found at $alacritty_script" - echo "Theme file updated, but Alacritty theme not switched" - fi + echo "Alacritty follows System Settings → Appearance (no rebuild). Neovim theme file updated above." else # Other platforms - just update the theme file