summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Pocock <mattpocockvoice@gmail.com>2026-10-09 09:47:11 +0100
committerMatt Pocock <mattpocockvoice@gmail.com>2026-10-09 09:47:11 +0100
commit621f35ba1499fcaf3d70afe84b8ffba494b1f156 (patch)
tree1fa239b160a5323cc352cf77f90ffb000ea9f91d
parentb0618bc436ad893b3c5e84e55fba86586d34a404 (diff)
wizard: template fixes (#1220, #1142, #1081, #1041, #1003)wizard-template-fixes-2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
-rw-r--r--.changeset/wizard-template-fixes-2.md5
-rw-r--r--skills/engineering/wizard/template.sh28
2 files changed, 26 insertions, 7 deletions
diff --git a/.changeset/wizard-template-fixes-2.md b/.changeset/wizard-template-fixes-2.md
new file mode 100644
index 0000000..937cf02
--- /dev/null
+++ b/.changeset/wizard-template-fixes-2.md
@@ -0,0 +1,5 @@
+---
+"mattpocock-skills": patch
+---
+
+`wizard` template fixes: `_existing` decodes a double-quoted `.env` value, so Enter-keeps-current no longer stores the quotes (#1220); stages run inside `run_wizard`, so editing the script mid-run can't kill it (#1142); `_clear` falls back to ANSI when `tput clear` fails (#1081); `write_env` sets the shell variable too (#1041); drop the unused `RED` (#1003).
diff --git a/skills/engineering/wizard/template.sh b/skills/engineering/wizard/template.sh
index 2d0de38..081ed3d 100644
--- a/skills/engineering/wizard/template.sh
+++ b/skills/engineering/wizard/template.sh
@@ -14,9 +14,9 @@ set -euo pipefail
if [[ -t 1 ]] && command -v tput >/dev/null 2>&1 && [[ "$(tput colors 2>/dev/null || echo 0)" -ge 8 ]]; then
BOLD=$(tput bold); DIM=$(tput dim); RESET=$(tput sgr0)
- BLUE=$(tput setaf 4); GREEN=$(tput setaf 2); YELLOW=$(tput setaf 3); RED=$(tput setaf 1)
+ BLUE=$(tput setaf 4); GREEN=$(tput setaf 2); YELLOW=$(tput setaf 3)
else
- BOLD=""; DIM=""; RESET=""; BLUE=""; GREEN=""; YELLOW=""; RED=""
+ BOLD=""; DIM=""; RESET=""; BLUE=""; GREEN=""; YELLOW=""
fi
# Author sets this at the top of the stages section.
@@ -32,7 +32,8 @@ SKIPPED=() # things we couldn't do (e.g. gh missing)
# output isn't a terminal, so piped logs stay readable.
_clear() {
[[ -t 1 ]] || return 0
- if command -v tput >/dev/null 2>&1; then tput clear; else printf '\033[2J\033[3J\033[H'; fi
+ if command -v tput >/dev/null 2>&1 && tput clear 2>/dev/null; then return 0; fi
+ printf '\033[2J\033[3J\033[H'
}
# banner "Title" shows the opening frame: what this wizard does.
@@ -88,12 +89,17 @@ confirm() {
[[ "$reply" =~ ^[Yy] ]]
}
-# _existing KEY: current value of KEY in ENV_FILE, if any, with write_env's quoting undone.
+# _existing KEY: current value of KEY in ENV_FILE, if any, with write_env's single
+# quotes or a plain dotenv double-quoted value undone.
_existing() {
[[ -f "$ENV_FILE" ]] || return 1
local line value sq="'\\''"; line=$(grep -E "^${1}=" "$ENV_FILE" | tail -n1) || return 1
value="${line#*=}"
- if [[ "$value" == \'*\' ]]; then value="${value:1:${#value}-2}"; value="${value//"$sq"/\'}"; fi
+ if [[ "$value" == \'*\' ]]; then value="${value:1:${#value}-2}"; value="${value//"$sq"/\'}"
+ elif [[ "$value" == \"*\" ]]; then
+ value="${value:1:${#value}-2}"
+ [[ "$value" == *[\\\$\"]* ]] && return 1 # escapes, $ or ": can't decode safely; ask again
+ fi
printf '%s' "$value"
}
@@ -129,8 +135,8 @@ ask_secret() {
}
# write_env KEY VALUE upserts KEY='VALUE' into ENV_FILE (replaces any existing
-# line). Idempotent. Creates ENV_FILE at mode 0600; writes through a symlink
-# and keeps an existing file's mode.
+# line) and sets $KEY. Idempotent. Creates ENV_FILE at mode 0600; writes through
+# a symlink and keeps an existing file's mode.
write_env() {
local key="$1" value="$2" tmp sq="'\\''"
[[ -e "$ENV_FILE" ]] || (umask 077 && : > "$ENV_FILE")
@@ -139,6 +145,7 @@ write_env() {
printf "%s='%s'\n" "$key" "${value//\'/$sq}" >> "$tmp"
cat "$tmp" > "$ENV_FILE"
rm -f "$tmp"
+ printf -v "$key" '%s' "$value"
WRITTEN_ENV+=("$key")
printf ' %s✓ wrote%s %s → %s\n' "$GREEN" "$RESET" "$key" "$ENV_FILE"
}
@@ -187,8 +194,12 @@ finish() {
# ──────────────────────────────────────────────────────────────────────────
# STAGES: author this section. One stage() per step the human takes.
# Replace the example below. Set TOTAL_STAGES to match the stages you write.
+# Keep every stage inside run_wizard and the last line as is: bash then parses
+# the whole file before the first prompt, so an edit mid-run can't break it.
# ──────────────────────────────────────────────────────────────────────────
+run_wizard() {
+
TOTAL_STAGES=1
banner "Stripe setup"
@@ -207,3 +218,6 @@ set_secret STRIPE_SECRET_KEY "$STRIPE_SECRET_KEY" # CI needs this one
# ──────────────────────────────────────────────────────────────────────────
finish
+}
+
+run_wizard "$@"; exit