mirror of
https://github.com/basecamp/omarchy.git
synced 2026-02-17 15:25:37 +00:00
Slim down
This commit is contained in:
@@ -7,73 +7,33 @@ COLORS_FILE="$1"
|
|||||||
TEMPLATES_DIR="$2"
|
TEMPLATES_DIR="$2"
|
||||||
OUTPUT_DIR="$3"
|
OUTPUT_DIR="$3"
|
||||||
|
|
||||||
if [[ -z "$COLORS_FILE" || -z "$TEMPLATES_DIR" || -z "$OUTPUT_DIR" ]]; then
|
if [[ -z $COLORS_FILE || -z $TEMPLATES_DIR || -z $OUTPUT_DIR ]]; then
|
||||||
echo "Usage: omarchy-theme-render <colors_toml> <templates_dir> <output_dir>"
|
echo "Usage: omarchy-theme-render <colors_toml> <templates_dir> <output_dir>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$COLORS_FILE" ]]; then
|
# Old themes don't have color files
|
||||||
echo "Error: Colors file '$COLORS_FILE' not found"
|
[[ ! -f "$COLORS_FILE" ]] && exit 1
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -d "$TEMPLATES_DIR" ]]; then
|
|
||||||
echo "Error: Templates directory '$TEMPLATES_DIR' not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# Configs are rendered into the output directory
|
||||||
mkdir -p "$OUTPUT_DIR"
|
mkdir -p "$OUTPUT_DIR"
|
||||||
|
|
||||||
# Create a temporary sed script
|
# 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)
|
||||||
|
sed 's/=/:/' "$COLORS_FILE" | yq -r 'to_entries[] | "s|{{ \(.key) }}|\(.value)|g"' > "$SED_SCRIPT"
|
||||||
# Read the TOML file line by line
|
|
||||||
while IFS='=' read -r key value; do
|
|
||||||
# Skip comments and empty lines
|
|
||||||
[[ "$key" =~ ^[[:space:]]*# ]] && continue
|
|
||||||
[[ -z "$key" ]] && continue
|
|
||||||
|
|
||||||
# Skip lines without values (like [headers])
|
|
||||||
[[ -z "$value" ]] && continue
|
|
||||||
|
|
||||||
# Trim whitespace from key and value
|
|
||||||
key=$(echo "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
||||||
value=$(echo "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
|
|
||||||
|
|
||||||
# Remove quotes from string values
|
|
||||||
value="${value%\"}"
|
|
||||||
value="${value#\"}"
|
|
||||||
value="${value%\'}"
|
|
||||||
value="${value#\'}"
|
|
||||||
|
|
||||||
# Add replacement command to sed script
|
|
||||||
# We use | as delimiter to avoid issues with / in paths or values, though colors are usually hex
|
|
||||||
# Escaping special regex characters in value would be ideal, but for hex codes it's fine.
|
|
||||||
# We replace {{ key }} with the value
|
|
||||||
echo "s|{{ $key }}|$value|g" >> "$SED_SCRIPT"
|
|
||||||
|
|
||||||
done < "$COLORS_FILE"
|
|
||||||
|
|
||||||
# Process each template file
|
# Process each template file
|
||||||
count=0
|
|
||||||
skipped=0
|
|
||||||
# Enable nullglob to handle case where no templates exist
|
# Enable nullglob to handle case where no templates exist
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
for tpl in "$TEMPLATES_DIR"/*.tpl; do
|
for tpl in "$TEMPLATES_DIR"/*.tpl; do
|
||||||
filename=$(basename "$tpl" .tpl)
|
filename=$(basename "$tpl" .tpl)
|
||||||
output_path="$OUTPUT_DIR/$filename"
|
output_path="$OUTPUT_DIR/$filename"
|
||||||
|
|
||||||
# If the file already exists in the output directory (copied from theme specific folder),
|
|
||||||
# do NOT overwrite it.
|
|
||||||
if [[ -f "$output_path" ]]; then
|
|
||||||
# echo "Skipping $filename (explicit config exists)"
|
|
||||||
((skipped++))
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
# 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"
|
||||||
((count++))
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
rm "$SED_SCRIPT"
|
rm "$SED_SCRIPT"
|
||||||
echo "Rendered $count templates to $OUTPUT_DIR (skipped $skipped existing)"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user