From e8bcad0c23135d67bedf358f4144f80cbb5316a0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 3 Jan 2026 18:18:19 -0800 Subject: [PATCH] Fix template generation for rgb colors --- bin/omarchy-theme-set-templates | 18 ++++++++++++++++++ default/themed/hyprlock.conf.tpl | 10 +++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-theme-set-templates b/bin/omarchy-theme-set-templates index 9119d9a5..11b3559c 100755 --- a/bin/omarchy-theme-set-templates +++ b/bin/omarchy-theme-set-templates @@ -4,13 +4,31 @@ TEMPLATES_DIR="$OMARCHY_PATH/default/themed" NEXT_THEME_DIR="$HOME/.config/omarchy/current/next-theme" COLORS_FILE="$NEXT_THEME_DIR/colors.toml" +# Convert hex color to decimal RGB (e.g., "#1e1e2e" -> "30,30,46") +hex_to_rgb() { + local hex="${1#\#}" + printf "%d,%d,%d" "0x${hex:0:2}" "0x${hex:2:2}" "0x${hex:4:2}" +} + # Only generate dynamic templates for themes with a colors.toml definition if [[ -f $COLORS_FILE ]]; 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) + + # Generate standard and _strip substitutions sed 's/=/:/' "$COLORS_FILE" | yq -r 'to_entries[] | "s|{{ \(.key) }}|\(.value)|g", "s|{{ \(.key)_strip }}|\(.value | sub("^#";""))|g"' > "$sed_script" + # Generate _rgb substitutions for hex colors + while IFS='=' read -r key value; do + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs | tr -d '"') + if [[ $value =~ ^# ]]; then + rgb=$(hex_to_rgb "$value") + echo "s|{{ ${key}_rgb }}|${rgb}|g" >> "$sed_script" + fi + done < "$COLORS_FILE" + shopt -s nullglob for tpl in "$TEMPLATES_DIR"/*.tpl; do filename=$(basename "$tpl" .tpl) diff --git a/default/themed/hyprlock.conf.tpl b/default/themed/hyprlock.conf.tpl index 07eea9b7..1b4cac3c 100644 --- a/default/themed/hyprlock.conf.tpl +++ b/default/themed/hyprlock.conf.tpl @@ -1,5 +1,5 @@ -$color = {{ background }} -$inner_color = {{ background }} -$outer_color = {{ foreground }} -$font_color = {{ foreground }} -$check_color = {{ accent }} +$color = rgba({{ background_rgb }}, 1.0) +$inner_color = rgba({{ background_rgb }}, 0.8) +$outer_color = rgba({{ foreground_rgb }}, 1.0) +$font_color = rgba({{ foreground_rgb }}, 1.0) +$check_color = rgba({{ accent_rgb }}, 1.0)