Replace yq with pure bash for TOML parsing (#4171)

* Replace yq with pure bash for TOML parsing

The yq-based parsing only worked with jq/yq v3 and broke with go-yq v4.
This change removes the yq and uses bash for parsing. Some additional improvments:
- Handles single and double quoted values
- Strips inline comments (e.g. "#hex" #comment)

* Remove the no-longer-needed yq packages

---------

Co-authored-by: David Heinemeier Hansson <david@hey.com>
This commit is contained in:
Dominik
2026-01-09 15:39:07 +01:00
committed by GitHub
parent 0b5ba427b2
commit 4cec214a53
3 changed files with 10 additions and 14 deletions

View File

@@ -13,22 +13,21 @@ hex_to_rgb() {
# Only generate dynamic templates for themes with a colors.toml definition # Only generate dynamic templates for themes with a colors.toml definition
if [[ -f $COLORS_FILE ]]; then 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_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 while IFS='=' read -r key value; do
key=$(echo "$key" | xargs) key="${key//[\"\' ]/}" # strip quotes and spaces from key
value=$(echo "$value" | xargs | tr -d '"') [[ $key && $key != \#* ]] || continue # skip empty lines and comments
value="${value#*[\"\']}"
value="${value%%[\"\']*}" # extract value between quotes (ignores inline comments)
printf 's|{{ %s }}|%s|g\n' "$key" "$value" # {{ key }} -> value
printf 's|{{ %s_strip }}|%s|g\n' "$key" "${value#\#}" # {{ key_strip }} -> value without leading #
if [[ $value =~ ^# ]]; then if [[ $value =~ ^# ]]; then
rgb=$(hex_to_rgb "$value") rgb=$(hex_to_rgb "$value")
echo "s|{{ ${key}_rgb }}|${rgb}|g" >> "$sed_script" echo "s|{{ ${key}_rgb }}|${rgb}|g"
fi fi
done < "$COLORS_FILE" done <"$COLORS_FILE" >"$sed_script"
shopt -s nullglob shopt -s nullglob
@@ -39,7 +38,7 @@ if [[ -f $COLORS_FILE ]]; then
# Don't overwrite configs already exists in the output directory (copied from theme specific folder) # Don't overwrite configs already exists in the output directory (copied from theme specific folder)
if [[ ! -f $output_path ]]; then if [[ ! -f $output_path ]]; then
sed -f "$sed_script" "$tpl" > "$output_path" sed -f "$sed_script" "$tpl" >"$output_path"
fi fi
done done

View File

@@ -144,5 +144,4 @@ xmlstarlet
xournalpp xournalpp
yaru-icon-theme yaru-icon-theme
yay yay
yq
zoxide zoxide

View File

@@ -1,7 +1,5 @@
echo "Migrate to new theme setup" echo "Migrate to new theme setup"
omarchy-pkg-add yq
# Move user-added backgrounds from Omarchy theme folders to user config # Move user-added backgrounds from Omarchy theme folders to user config
OMARCHY_DIR="$HOME/.local/share/omarchy" OMARCHY_DIR="$HOME/.local/share/omarchy"
USER_BACKGROUNDS_DIR="$HOME/.config/omarchy/backgrounds" USER_BACKGROUNDS_DIR="$HOME/.config/omarchy/backgrounds"