nix/scripts/theme
2026-02-10 20:53:05 -05:00

116 lines
3.2 KiB
Bash
Executable file

#!/bin/sh
require() {
for cmd in "$@"; do
command -v "$cmd" >/dev/null 2>&1 || {
echo "theme: missing dependency: $cmd" >&2
exit 1
}
done
}
require gsettings
themes="daylight
midnight"
# --- Selection ---
if [ -n "$1" ]; then
theme="$1"
else
case "$(uname)" in
Linux)
if [ "$XDG_SESSION_TYPE" = "wayland" ]; then
require rofi
theme="$(printf "%s\n" "$themes" | rofi -dmenu -p 'theme')"
else
require dmenu
theme="$(printf "%s\n" "$themes" | dmenu -p 'select theme: ')"
fi
;;
Darwin)
as_list="$(printf "%s\n" "$themes" | awk 'NF{printf "\"%s\",", $0}' | sed 's/,$//')"
theme="$(
osascript <<EOF
set theList to {$as_list}
set chosenTheme to (choose from list theList with title "Theme" with prompt "Pick a theme" OK button name "Apply" cancel button name "Cancel" without empty selection allowed)
if chosenTheme is false then
return ""
else
return item 1 of chosenTheme
end if
EOF
)"
;;
*) exit 1 ;;
esac
fi
[ -z "$theme" ] && exit 1
echo "$themes" | grep -Fxq "$theme" || exit 1
# --- Platform ---
case "$(uname)" in
Linux)
# GTK color scheme
case "$theme" in
midnight) gsettings set org.gnome.desktop.interface color-scheme 'prefer-dark' ;;
daylight) gsettings set org.gnome.desktop.interface color-scheme 'prefer-light' ;;
esac
# Hyprland: runtime border colors + waybar
if [ "$XDG_CURRENT_DESKTOP" = "Hyprland" ] && command -v hyprctl >/dev/null 2>&1; then
case "$theme" in
midnight)
hyprctl keyword general:col.active_border "rgb(e0e0e0)"
hyprctl keyword general:col.inactive_border "rgb(121212)"
;;
daylight)
hyprctl keyword general:col.active_border "rgb(1a1a1a)"
hyprctl keyword general:col.inactive_border "rgb(f5f5f5)"
;;
esac
waybar_themes="${XDG_CONFIG_HOME:-$HOME/.config}/waybar/themes"
[ -f "$waybar_themes/$theme.css" ] && {
ln -sf "$waybar_themes/$theme.css" "$waybar_themes/theme.css"
pkill -USR2 waybar
}
fi
;;
Darwin)
case "$theme" in
daylight) osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to false' 2>/dev/null || true ;;
midnight) osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to true' 2>/dev/null || true ;;
esac
;;
esac
# --- Cross-platform ---
# Tmux
if [ -n "$TMUX" ]; then
tmux_themes="${XDG_CONFIG_HOME:-$HOME/.config}/tmux/themes"
[ -f "$tmux_themes/$theme.conf" ] && tmux source "$tmux_themes/$theme.conf"
tmux setenv -g THEME "$theme"
fi
# Claude CLI
if command -v claude >/dev/null 2>&1 && command -v jq >/dev/null 2>&1; then
CLAUDE_CONFIG="${CLAUDE_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/claude}/.claude.json"
case "$theme" in
midnight) claude_theme='dark' ;;
daylight) claude_theme='light' ;;
esac
[ -f "$CLAUDE_CONFIG" ] && {
jq ".theme=\"$claude_theme\"" "$CLAUDE_CONFIG" > "$CLAUDE_CONFIG.tmp" &&
mv "$CLAUDE_CONFIG.tmp" "$CLAUDE_CONFIG"
}
fi
# Neovim instances
for socket in /run/user/"$(id -u)"/nvim.*.0 /tmp/nvim-*.sock; do
[ -S "$socket" ] && nvim --server "$socket" --remote-expr "luaeval('require(\"config.fzf_reload\").reload()')" 2>/dev/null || true
done