Sweep across the three script directories: features/scripts/utils,
core/system/scripts, themes/engine/scripts. 142 of 169 bash scripts
gained `set -e`; 27 already had it; the one Python helper
(nomarchy-haptic-touchpad) was skipped via shebang detection.
Why: bash's default behavior is to continue past a failed command,
which means a script that does "do A; do B; do C" leaves the system
in a half-applied state when B fails - and the user gets no signal.
Several recent fix commits (theme partial-apply, waybar reload race,
installer prewipe silent failures) all trace back to this. set -e
turns silent corruption into a loud abort the user can act on.
The 11 scripts with explicit `|| true` markers stay safe under set -e
because || true coerces the exit to zero; the markers continue to
mean "I deliberately tolerate this failure here."
Deliberate exception: nomarchy-menu runs WITHOUT set -e. It is an
interactive UX loop where action branches do `cmd; back_to <self>`
so a failed action would abort the script under set -e and the menu
would disappear without feedback. Soft-failure - menu re-displays,
user picks again - is the right semantic. Documented inline.
Validation: bash -n on every modified script (zero failures). The
new pre-commit hook (27f5663) was just updated to filter by shebang
so it doesn't try to bash-syntax-check the Python helper - that
filter was uncovered by this sweep.
Risk: set -e can surface latent bugs in scripts that previously
relied on silent continuation. If anything breaks, it's a real bug
that was already broken and is now visible. Easy per-script revert
if any UX glitches show up.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.6 KiB
Bash
Executable File
48 lines
1.6 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
TEMPLATES_DIR="$NOMARCHY_PATH/themes/templates"
|
|
USER_TEMPLATES_DIR="$HOME/.config/nomarchy/themes/templates"
|
|
NEXT_THEME_DIR="$HOME/.config/nomarchy/current/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
|
|
sed_script=$(mktemp)
|
|
|
|
while IFS='=' read -r key value; do
|
|
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"
|
|
fi
|
|
done <"$COLORS_FILE" >"$sed_script"
|
|
|
|
shopt -s nullglob
|
|
|
|
# Process user templates first, then built-in templates (user overrides built-in)
|
|
for tpl in "$USER_TEMPLATES_DIR"/*.tpl "$TEMPLATES_DIR"/*.tpl; do
|
|
filename=$(basename "$tpl" .tpl)
|
|
output_path="$NEXT_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
|