Files
omarchy/bin/omarchy-theme-set
David Heinemeier Hansson 8ea021744d Combine render into -set
2026-01-01 11:55:03 -07:00

78 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
if [[ -z $1 && $1 != "CNCLD" ]]; then
echo "Usage: omarchy-theme-set <theme-name>"
exit 1
fi
THEMES_DIR="$HOME/.config/omarchy/themes/"
CURRENT_THEME_DIR="$HOME/.config/omarchy/current/theme"
THEME_NAME=$(echo "$1" | sed -E 's/<[^>]+>//g' | tr '[:upper:]' '[:lower:]' | tr ' ' '-')
THEME_PATH="$THEMES_DIR/$THEME_NAME"
# Check if the theme entered exists
if [[ ! -d "$THEME_PATH" ]]; then
echo "Theme '$THEME_NAME' does not exist in $THEMES_DIR"
exit 1
fi
# Setup theme directory
if [[ -L "$CURRENT_THEME_DIR" ]]; then
rm "$CURRENT_THEME_DIR"
elif [[ -d "$CURRENT_THEME_DIR" ]]; then
rm -rf "$CURRENT_THEME_DIR"
fi
mkdir -p "$CURRENT_THEME_DIR"
# Copy static configs
cp -r "$THEME_PATH/"* "$CURRENT_THEME_DIR/" 2>/dev/null
# Generate dynamic configs
TEMPLATES_DIR="$THEMES_DIR/templates.d"
COLORS_FILE="$THEME_PATH/colors.toml"
if [[ -f $COLORS_FILE && -d $TEMPLATES_DIR ]]; then
# Parse TOML using yq (treating it as YAML since the flat key=value structure is compatible)
# We convert 'key = value' to 'key: value' to make it valid YAML, then use yq/jq to generate the replacement commands.
SED_SCRIPT=$(mktemp)
sed 's/=/:/' "$COLORS_FILE" | yq -r 'to_entries[] | "s|{{ \(.key) }}|\(.value)|g"' > "$SED_SCRIPT"
# Process each template file
shopt -s nullglob
for tpl in "$TEMPLATES_DIR"/*.tpl; do
filename=$(basename "$tpl" .tpl)
output_path="$CURRENT_THEME_DIR/$filename"
# Don't overwrite configs already exists in the output directory (copied from theme specific folder)
if [[ ! -f $output_path ]]; then
sed -f "$SED_SCRIPT" "$tpl" > "$output_path"
fi
done
rm "$SED_SCRIPT"
fi
# Change background with theme
omarchy-theme-bg-next
# Restart components to apply new theme
if pgrep -x waybar >/dev/null; then
omarchy-restart-waybar
fi
omarchy-restart-swayosd
omarchy-restart-terminal
hyprctl reload
pkill -SIGUSR2 btop
makoctl reload
# Change gnome, browser, vscode, cursor themes
omarchy-theme-set-gnome
omarchy-theme-set-browser
omarchy-theme-set-vscode
omarchy-theme-set-cursor
omarchy-theme-set-obsidian
# Call hook on theme set
omarchy-hook theme-set "$THEME_NAME"