feat: unify theme switching with cross-platform script
- Create unified theme.sh script that works on both WSL and macOS - Update fish alias to use new unified script instead of WSL-specific one - Maintain backward compatibility with existing theme command - Update documentation to reflect unified approach - Script automatically detects platform and calls appropriate functionality
This commit is contained in:
parent
c8a7e3fb34
commit
072f197660
3 changed files with 132 additions and 27 deletions
|
|
@ -1,46 +1,50 @@
|
||||||
# Alacritty Theme Synchronization
|
# Unified Theme Switching
|
||||||
|
|
||||||
Simple theme switching for Alacritty that allows you to switch between Catppuccin light and dark themes.
|
Unified theme switching that works across platforms (WSL and macOS) for Neovim, Alacritty, and Windows Terminal.
|
||||||
|
|
||||||
**This solution uses Nix conditional configuration with a simple script to switch themes.**
|
**This solution uses a single `theme` command that detects the platform and switches themes appropriately.**
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
1. The Nix configuration has a boolean variable `isLightTheme` in `home.nix`
|
1. The `theme` command detects the platform (WSL vs macOS)
|
||||||
2. When `isLightTheme = true` → Catppuccin Latte (light theme)
|
2. **On WSL:** Updates Neovim, Windows Terminal, and Windows system theme
|
||||||
3. When `isLightTheme = false` → Catppuccin Mocha (dark theme)
|
3. **On macOS:** Updates Neovim and Alacritty themes via Nix configuration
|
||||||
4. A script updates this variable and rebuilds the configuration
|
4. Uses the same `nvim_color_scheme` file for Neovim on both platforms
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
1. **The configuration is already set up!** Your Alacritty is currently using the light theme.
|
1. **The configuration is already set up!** The `theme` command is available as a fish alias.
|
||||||
|
|
||||||
2. **To switch themes, use the script:**
|
2. **To switch themes, use the unified command:**
|
||||||
```bash
|
```bash
|
||||||
./scripts/switch-alacritty-theme.sh light # Switch to light theme
|
theme light # Switch to light theme
|
||||||
./scripts/switch-alacritty-theme.sh dark # Switch to dark theme
|
theme dark # Switch to dark theme
|
||||||
./scripts/switch-alacritty-theme.sh toggle # Toggle between themes
|
|
||||||
./scripts/switch-alacritty-theme.sh status # Show current theme
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Manual Theme Switching
|
### Unified Theme Command
|
||||||
```bash
|
```bash
|
||||||
# Switch to light theme
|
# Switch to light theme (works on WSL and macOS)
|
||||||
./scripts/switch-alacritty-theme.sh light
|
theme light
|
||||||
|
|
||||||
# Switch to dark theme
|
# Switch to dark theme (works on WSL and macOS)
|
||||||
./scripts/switch-alacritty-theme.sh dark
|
theme dark
|
||||||
|
|
||||||
# Toggle between themes
|
|
||||||
./scripts/switch-alacritty-theme.sh toggle
|
|
||||||
|
|
||||||
# Check current theme
|
|
||||||
./scripts/switch-alacritty-theme.sh status
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Manual Configuration
|
### 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:
|
You can also manually edit `nixos/home/danny/home.nix` and change:
|
||||||
```nix
|
```nix
|
||||||
isLightTheme = true; # for light theme
|
isLightTheme = true; # for light theme
|
||||||
|
|
@ -50,9 +54,12 @@ Then run: `cd nixos && sudo darwin-rebuild switch --flake .#Daniel-Macbook-Air`
|
||||||
|
|
||||||
## Files
|
## Files
|
||||||
|
|
||||||
- `scripts/switch-alacritty-theme.sh` - Script to switch themes
|
- `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)
|
- `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
|
- `nixos/home/danny/home.nix` - Contains the conditional Alacritty configuration
|
||||||
|
- `bashscripts/wsl_theme.sh` - Legacy WSL script (replaced by theme.sh)
|
||||||
|
|
||||||
## Theme Colors
|
## Theme Colors
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
programs.fish = {
|
programs.fish = {
|
||||||
enable = true;
|
enable = true;
|
||||||
shellAliases = {
|
shellAliases = {
|
||||||
theme = "bash ~/dotfiles/bashscripts/wsl_theme.sh";
|
theme = "bash ~/dotfiles/scripts/theme.sh";
|
||||||
music = "mpv --no-video --log-file=~/music_history.log \"$(find /mnt/c/Users/DNTH/Music/ -type f \\( -name '*.mp3' -o -name '*.wav' -o -name '*.flac' -o -name '*.m4a' -o -name '*.ogg' \\) | fzf)\"";
|
music = "mpv --no-video --log-file=~/music_history.log \"$(find /mnt/c/Users/DNTH/Music/ -type f \\( -name '*.mp3' -o -name '*.wav' -o -name '*.flac' -o -name '*.m4a' -o -name '*.ogg' \\) | fzf)\"";
|
||||||
};
|
};
|
||||||
interactiveShellInit = ''
|
interactiveShellInit = ''
|
||||||
|
|
|
||||||
98
scripts/theme.sh
Executable file
98
scripts/theme.sh
Executable file
|
|
@ -0,0 +1,98 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Unified theme switching script for WSL and macOS
|
||||||
|
# This script handles theme switching for both platforms
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
color_scheme=$1
|
||||||
|
|
||||||
|
# Validate user input
|
||||||
|
if [[ "$color_scheme" != "dark" && "$color_scheme" != "light" ]]; then
|
||||||
|
echo "Usage: theme {dark|light}"
|
||||||
|
echo ""
|
||||||
|
echo "This command switches themes for:"
|
||||||
|
echo " - Neovim (via nvim_color_scheme file)"
|
||||||
|
echo " - Alacritty (via Nix configuration on macOS)"
|
||||||
|
echo " - Windows Terminal (via settings.json on WSL)"
|
||||||
|
echo " - Windows system theme (on WSL)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the directory where this script is located
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
DOTFILES_DIR="$(dirname "$SCRIPT_DIR")"
|
||||||
|
|
||||||
|
# Write theme to nvim color scheme file (works on both platforms)
|
||||||
|
nvim_color_theme_path=~/.local/share/nvim_color_scheme
|
||||||
|
mkdir -p "$(dirname "$nvim_color_theme_path")"
|
||||||
|
echo "$color_scheme" > "$nvim_color_theme_path"
|
||||||
|
echo "Updated Neovim theme: $color_scheme"
|
||||||
|
|
||||||
|
# Detect platform and handle platform-specific theme switching
|
||||||
|
if [[ -n "$WSL_DISTRO_NAME" ]]; then
|
||||||
|
# WSL platform - handle Windows Terminal and system theme
|
||||||
|
echo "Detected WSL platform"
|
||||||
|
|
||||||
|
# Check that all relevant files exist
|
||||||
|
windows_username=$(powershell.exe '$env:UserName' | tr -d '\r\n')
|
||||||
|
windows_terminal_settings_path="/mnt/c/Users/${windows_username}/AppData/Local/Packages/Microsoft.WindowsTerminal_8wekyb3d8bbwe/LocalState/settings.json"
|
||||||
|
dark_mode_config_path="$DOTFILES_DIR/assets/windows_terminal/dark.settings.json"
|
||||||
|
light_mode_config_path="$DOTFILES_DIR/assets/windows_terminal/light.settings.json"
|
||||||
|
|
||||||
|
if [ ! -f "$light_mode_config_path" ]; then
|
||||||
|
echo "error: light_mode_config_path missing"
|
||||||
|
echo "expected: $light_mode_config_path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$dark_mode_config_path" ]; then
|
||||||
|
echo "error: dark_mode_config_path missing"
|
||||||
|
echo "expected: $dark_mode_config_path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "$windows_terminal_settings_path" ]; then
|
||||||
|
echo "error: windows terminal settings path missing"
|
||||||
|
echo "expected: $windows_terminal_settings_path"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Update Windows Terminal settings
|
||||||
|
if [ "$color_scheme" = 'dark' ]; then
|
||||||
|
cp "$dark_mode_config_path" "$windows_terminal_settings_path"
|
||||||
|
echo "Updated Windows Terminal: dark theme"
|
||||||
|
echo "Switching Windows system theme to dark..."
|
||||||
|
powershell.exe -Command "start C:\Windows\Resources\Themes\dark.theme"
|
||||||
|
powershell.exe "timeout /t 3; taskkill /im systemsettings.exe /f"
|
||||||
|
else
|
||||||
|
cp "$light_mode_config_path" "$windows_terminal_settings_path"
|
||||||
|
echo "Updated Windows Terminal: light theme"
|
||||||
|
echo "Switching Windows system theme to light..."
|
||||||
|
powershell.exe -Command "start C:\Windows\Resources\Themes\aero.theme"
|
||||||
|
powershell.exe "timeout /t 3; taskkill /im systemsettings.exe /f"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Setting Sound Schema to None"
|
||||||
|
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
|
||||||
|
|
||||||
|
else
|
||||||
|
# Other platforms - just update the theme file
|
||||||
|
echo "Detected other platform - only updating Neovim theme file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Theme switching complete: $color_scheme"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue