fix(shopify): parse every theme and keep match variables local

The dynamic theme completion split the `theme list --json` payload on
"${json//\{/$'\n'}", which substitutes a literal $'\n' rather than a newline.
Only the first theme was ever offered. Split on a newline held in a variable
instead.

Both completion helpers used =~ and (#b) backreferences without declaring
$match, leaving match, MATCH, mbegin and mend set in the user's shell.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LNDR8NjvPSgHbjcQurMHW9
This commit is contained in:
Robby Russell
2026-09-04 14:51:22 -07:00
co-authored by Claude Opus 5
parent 338a1131c8
commit 419fc5e9b5
+8 -1
View File
@@ -11,6 +11,9 @@ _shopify_environments() {
setopt localoptions extendedglob
local -a envs
local file line
# (#b) backreferences set $match, which would otherwise be left global.
local MATCH MBEGIN MEND
local -a match mbegin mend
for file in shopify.theme.toml shopify.app.toml; do
[[ -r "$file" ]] || continue
for line in ${(f)"$(< $file)"}; do
@@ -31,6 +34,10 @@ _shopify_themes() {
local cache_file="$ZSH_CACHE_DIR/shopify-themes${key: -100}"
local -a themes fresh
local json split entry id name role
# $match and friends are set by =~ and would otherwise be left global.
local MATCH MBEGIN MEND
local -a match mbegin mend
local nl=$'\n'
# Reuse the cached list for five minutes.
fresh=(${cache_file}(Nms-300))
@@ -39,7 +46,7 @@ _shopify_themes() {
else
json="$(command shopify theme list --json 2>/dev/null)" || return 1
# One chunk per object, in zsh, so there is no dependency on jq.
split="${json//\{/$'\n'}"
split="${json//\{/$nl}"
for entry in ${(f)split}; do
id="" name="" role=""
[[ $entry =~ '"id":[[:space:]]*([0-9]+)' ]] && id=$match[1]