feat: add theme status and toggle commands
- Add 'theme status' command to show current theme status across platforms - Add 'theme toggle' command to switch between light and dark themes - Improve toggle logic to read current theme from platform-specific sources - Update documentation to include new commands - Maintain backward compatibility with existing theme light/dark commands
This commit is contained in:
parent
072f197660
commit
6355fa64d3
2 changed files with 121 additions and 7 deletions
|
|
@ -19,6 +19,8 @@ Unified theme switching that works across platforms (WSL and macOS) for Neovim,
|
||||||
```bash
|
```bash
|
||||||
theme light # Switch to light theme
|
theme light # Switch to light theme
|
||||||
theme dark # Switch to dark theme
|
theme dark # Switch to dark theme
|
||||||
|
theme toggle # Toggle between light and dark themes
|
||||||
|
theme status # Show current theme status
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
@ -30,6 +32,12 @@ theme light
|
||||||
|
|
||||||
# Switch to dark theme (works on WSL and macOS)
|
# Switch to dark theme (works on WSL and macOS)
|
||||||
theme dark
|
theme dark
|
||||||
|
|
||||||
|
# Toggle between light and dark themes
|
||||||
|
theme toggle
|
||||||
|
|
||||||
|
# Show current theme status
|
||||||
|
theme status
|
||||||
```
|
```
|
||||||
|
|
||||||
### What Gets Updated
|
### What Gets Updated
|
||||||
|
|
|
||||||
120
scripts/theme.sh
120
scripts/theme.sh
|
|
@ -5,19 +5,125 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
color_scheme=$1
|
# Helper functions
|
||||||
|
show_usage() {
|
||||||
# Validate user input
|
echo "Usage: theme {dark|light|toggle|status}"
|
||||||
if [[ "$color_scheme" != "dark" && "$color_scheme" != "light" ]]; then
|
echo ""
|
||||||
echo "Usage: theme {dark|light}"
|
echo "Commands:"
|
||||||
|
echo " dark - Switch to dark theme"
|
||||||
|
echo " light - Switch to light theme"
|
||||||
|
echo " toggle - Toggle between light and dark themes"
|
||||||
|
echo " status - Show current theme status"
|
||||||
echo ""
|
echo ""
|
||||||
echo "This command switches themes for:"
|
echo "This command switches themes for:"
|
||||||
echo " - Neovim (via nvim_color_scheme file)"
|
echo " - Neovim (via nvim_color_scheme file)"
|
||||||
echo " - Alacritty (via Nix configuration on macOS)"
|
echo " - Alacritty (via Nix configuration on macOS)"
|
||||||
echo " - Windows Terminal (via settings.json on WSL)"
|
echo " - Windows Terminal (via settings.json on WSL)"
|
||||||
echo " - Windows system theme (on WSL)"
|
echo " - Windows system theme (on WSL)"
|
||||||
exit 1
|
}
|
||||||
fi
|
|
||||||
|
show_status() {
|
||||||
|
echo "Current theme status:"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Check Neovim theme
|
||||||
|
nvim_color_theme_path=~/.local/share/nvim_color_scheme
|
||||||
|
if [ -f "$nvim_color_theme_path" ]; then
|
||||||
|
nvim_theme=$(cat "$nvim_color_theme_path" | tr -d '\n')
|
||||||
|
echo " Neovim: $nvim_theme"
|
||||||
|
else
|
||||||
|
echo " Neovim: no theme file found"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check platform-specific themes
|
||||||
|
if [[ -n "$WSL_DISTRO_NAME" ]]; then
|
||||||
|
echo " Platform: WSL"
|
||||||
|
echo " Windows Terminal: configured via settings.json"
|
||||||
|
echo " Windows system theme: managed by theme command"
|
||||||
|
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
|
||||||
|
else
|
||||||
|
echo " Alacritty: config file not found"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo " Platform: other"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
toggle_theme() {
|
||||||
|
# Get current theme - prefer platform-specific detection
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Fallback to Neovim file if platform-specific detection didn't work
|
||||||
|
if [ -z "$current_theme" ]; then
|
||||||
|
nvim_color_theme_path=~/.local/share/nvim_color_scheme
|
||||||
|
if [ -f "$nvim_color_theme_path" ]; then
|
||||||
|
current_theme=$(cat "$nvim_color_theme_path" | tr -d '\n')
|
||||||
|
else
|
||||||
|
current_theme="light" # Default to light if no theme file exists
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Determine new theme
|
||||||
|
if [ "$current_theme" = "light" ]; then
|
||||||
|
new_theme="dark"
|
||||||
|
else
|
||||||
|
new_theme="light"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Toggling theme from $current_theme to $new_theme"
|
||||||
|
|
||||||
|
# Call the main script with the new theme
|
||||||
|
exec "$0" "$new_theme"
|
||||||
|
}
|
||||||
|
|
||||||
|
color_scheme=$1
|
||||||
|
|
||||||
|
# Handle special commands
|
||||||
|
case "$color_scheme" in
|
||||||
|
"status")
|
||||||
|
show_status
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"toggle")
|
||||||
|
toggle_theme
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"dark"|"light")
|
||||||
|
# Valid theme, continue with normal flow
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
show_usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Get the directory where this script is located
|
# Get the directory where this script is located
|
||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue