mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
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:
committed by
David Heinemeier Hansson
parent
ed9a4a45ba
commit
febd18ce84
@@ -13,22 +13,21 @@ hex_to_rgb() {
|
||||
|
||||
# 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 '"')
|
||||
key="${key//[\"\' ]/}" # strip quotes and spaces from key
|
||||
[[ $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
|
||||
rgb=$(hex_to_rgb "$value")
|
||||
echo "s|{{ ${key}_rgb }}|${rgb}|g" >> "$sed_script"
|
||||
echo "s|{{ ${key}_rgb }}|${rgb}|g"
|
||||
fi
|
||||
done < "$COLORS_FILE"
|
||||
done <"$COLORS_FILE" >"$sed_script"
|
||||
|
||||
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)
|
||||
if [[ ! -f $output_path ]]; then
|
||||
sed -f "$sed_script" "$tpl" > "$output_path"
|
||||
sed -f "$sed_script" "$tpl" >"$output_path"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
@@ -144,5 +144,4 @@ xmlstarlet
|
||||
xournalpp
|
||||
yaru-icon-theme
|
||||
yay
|
||||
yq
|
||||
zoxide
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
echo "Migrate to new theme setup"
|
||||
|
||||
omarchy-pkg-add yq
|
||||
|
||||
# Move user-added backgrounds from Omarchy theme folders to user config
|
||||
OMARCHY_DIR="$HOME/.local/share/omarchy"
|
||||
USER_BACKGROUNDS_DIR="$HOME/.config/omarchy/backgrounds"
|
||||
|
||||
Reference in New Issue
Block a user