64 lines
2.2 KiB
Bash
Executable File
64 lines
2.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# Central theme switcher (basic/.config/themes/scripts/switch-theme.sh).
|
|
#
|
|
# Usage: switch-theme.sh <theme-id> e.g. switch-theme.sh catppuccin-mocha
|
|
#
|
|
# Retargets the tracked `current` symlink to themes/<theme-id> and reloads
|
|
# every consumer that can be reloaded. Because `current` lives in the repo,
|
|
# the switch is a reviewable git change; re-stowing is not required since
|
|
# all consumers resolve through ~/.config/themes/current at runtime.
|
|
#
|
|
# A future non-Catppuccin theme only needs its own themes/<theme-id>/
|
|
# directory plus a row in themes/registry.conf — this script stays untouched.
|
|
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
echo "usage: $(basename "$0") <theme-id>" >&2
|
|
echo "available:" >&2
|
|
ls -1 "$(repo_root)/basic/.config/themes/themes" 2>/dev/null | grep -v '^registry.conf$' | sed 's/^/ /' >&2 || true
|
|
}
|
|
|
|
repo_root() {
|
|
local src="$0"
|
|
if command -v readlink >/dev/null 2>&1; then
|
|
src="$(readlink -f "$0")"
|
|
fi
|
|
cd "$(dirname "$src")/../../../.." && pwd
|
|
}
|
|
|
|
main() {
|
|
[[ $# -eq 1 ]] || { usage; exit 1; }
|
|
local theme_id="$1"
|
|
if [[ ! "$theme_id" =~ ^[a-z0-9][a-z0-9-]*$ ]]; then
|
|
echo "error: invalid theme-id '$theme_id'" >&2
|
|
exit 1
|
|
fi
|
|
|
|
local root
|
|
root="$(repo_root)"
|
|
local dest="$root/basic/.config/themes/themes/$theme_id"
|
|
local link="$root/basic/.config/themes/current"
|
|
|
|
[[ -d "$dest" ]] || { echo "error: unknown theme '$theme_id' (no $dest)" >&2; usage; exit 1; }
|
|
|
|
ln -sfn "themes/$theme_id" "$link"
|
|
echo "theme switched: current -> themes/$theme_id"
|
|
|
|
# Best-effort live reloads; every step is guarded so the switch
|
|
# succeeds even on machines without a running compositor.
|
|
if command -v hyprctl >/dev/null 2>&1; then
|
|
hyprctl reload >/dev/null 2>&1 || true
|
|
fi
|
|
if command -v tmux >/dev/null 2>&1 && [[ -n "${TMUX:-}" ]]; then
|
|
tmux source-file "$HOME/.config/tmux/tmux.conf" >/dev/null 2>&1 || true
|
|
fi
|
|
if pgrep -x waybar >/dev/null 2>&1; then
|
|
pkill -x waybar >/dev/null 2>&1 || true
|
|
(waybar >/dev/null 2>&1 &) || true
|
|
fi
|
|
echo "note: restart Neovim (or :colorscheme \$THEME_NVIM_COLORSCHEME) and open a new shell to pick up theme.env.sh."
|
|
}
|
|
|
|
main "$@"
|