Pull out the dynamic template rendering again, but simpler

This commit is contained in:
David Heinemeier Hansson
2026-01-01 12:06:31 -07:00
parent 8ea021744d
commit 3ecdcb262b
2 changed files with 30 additions and 31 deletions

26
bin/omarchy-theme-set-templates Executable file
View File

@@ -0,0 +1,26 @@
#!/bin/bash
TEMPLATES_DIR="$OMARCHY_PATH/themes/templates.d"
COLORS_FILE="$HOME/.config/omarchy/current/theme/colors.toml"
# 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)
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