Skip to content

Commit 02c40f4

Browse files
authored
Use ZSH_CONFIG for full install and prevent env resolver loops (#10)
1 parent af163be commit 02c40f4

7 files changed

Lines changed: 34 additions & 21 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ source ~/.zshrc
3838

3939
| Flag | What it does |
4040
|---|---|
41-
| `--full` | Also installs helper functions (`tq`, `td`, `tl`) by symlinking `temporal.zsh` into `~/.config/zsh/` |
41+
| `--full` | Also installs helper functions (`tq`, `td`, `tl`) by symlinking `temporal.zsh` into `$ZSH_CONFIG` (or `${ZSH_CUSTOM:-${ZSH:-$HOME/.oh-my-zsh}/custom}` when unset) |
4242
| `[path]` | Install to a custom plugins directory instead of `$ZSH_CUSTOM/plugins` |
4343

4444
```bash

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ else
100100
fi
101101

102102
if [[ "$full_mode" == "1" ]]; then
103-
zshc_dir="${ZSHC:-$HOME/.config/zsh}"
103+
zshc_dir="${ZSH_CONFIG:-${ZSH_CUSTOM:-${ZSH:-$HOME/.oh-my-zsh}/custom}}"
104104
helper_source="$target_dir/temporalctx.full.zsh"
105105
helper_target="$zshc_dir/temporal.zsh"
106106
mkdir -p "$zshc_dir"

temporalctx.plugin.zsh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,16 @@ _temporalctx_resolve_value() {
136136
printf '%s\n' "$value" | awk '
137137
{
138138
s = $0
139-
while (match(s, /\$\{[A-Za-z_][A-Za-z0-9_]*\}/)) {
140-
var = substr(s, RSTART + 2, RLENGTH - 3)
141-
val = ENVIRON[var]
142-
s = substr(s, 1, RSTART - 1) val substr(s, RSTART + RLENGTH)
139+
out = ""
140+
pos = 1
141+
while (match(substr(s, pos), /\$\{[A-Za-z_][A-Za-z0-9_]*\}/)) {
142+
mstart = pos + RSTART - 1
143+
out = out substr(s, pos, mstart - pos)
144+
var = substr(s, mstart + 2, RLENGTH - 3)
145+
out = out ENVIRON[var]
146+
pos = mstart + RLENGTH
143147
}
144-
print s
148+
print out substr(s, pos)
145149
}
146150
'
147151
}

tests/install_test.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ PATH="$tmp_root/bin:$PATH" HOME="$home2" "$REPO_ROOT/install.sh" "$custom_target
4444
[[ -L "$custom_target/temporalctx" || -d "$custom_target/temporalctx/.git" ]] || fail "custom target should install to <dir>/temporalctx"
4545
log "case passed: custom target"
4646

47-
# Test: --full installs opinionated helpers into ZSHC/temporal.zsh.
48-
log "case: --full installs opinionated helpers in ZSHC"
47+
# Test: --full installs opinionated helpers into ZSH_CONFIG/temporal.zsh.
48+
log "case: --full installs opinionated helpers in ZSH_CONFIG"
4949
home3="$tmp_root/home3"
50-
zshc3="$tmp_root/zshc3"
50+
zsh_config3="$tmp_root/zsh_config3"
5151
plugins3="$tmp_root/plugins3"
52-
mkdir -p "$home3" "$zshc3" "$plugins3"
53-
PATH="$tmp_root/bin:$PATH" HOME="$home3" ZSHC="$zshc3" "$REPO_ROOT/install.sh" --full "$plugins3" >"$tmp_root/install3.out" 2>"$tmp_root/install3.err"
54-
[[ -L "$zshc3/temporal.zsh" ]] || fail "--full should install temporal.zsh as a symlink in ZSHC"
55-
link_target="$(readlink "$zshc3/temporal.zsh")"
52+
mkdir -p "$home3" "$zsh_config3" "$plugins3"
53+
PATH="$tmp_root/bin:$PATH" HOME="$home3" ZSH_CONFIG="$zsh_config3" "$REPO_ROOT/install.sh" --full "$plugins3" >"$tmp_root/install3.out" 2>"$tmp_root/install3.err"
54+
[[ -L "$zsh_config3/temporal.zsh" ]] || fail "--full should install temporal.zsh as a symlink in ZSH_CONFIG"
55+
link_target="$(readlink "$zsh_config3/temporal.zsh")"
5656
assert_contains "$link_target" "temporalctx.full.zsh" "--full helper symlink should point to plugin helper file"
5757
log "case passed: --full helpers"
5858

tests/temporalctx_plugin_test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,13 @@ assert_contains "$out" "wrapped=ARGS: --address us-west-2.aws.api.temporal.io:72
197197
assert_contains "$out" "raw=ARGS: workflow list --limit 5" "opt-out env var should bypass wrapping"
198198
log "case passed: temporal wrapper"
199199

200+
# Test: env placeholders do not loop on self-referential exports.
201+
log "case: self-referential env values do not hang"
202+
out="$(PATH="$tmp_root/bin:$PATH" TEMPORAL_CONFIG="$cfg" TEMPORAL_CLOUD_PROD_API_KEY='${TEMPORAL_CLOUD_PROD_API_KEY}' zsh -c '
203+
source "'$REPO_ROOT'/temporalctx.plugin.zsh"
204+
echo "flags=$(_temporal_flags)"
205+
')"
206+
assert_contains "$out" "flags=--address us-west-2.aws.api.temporal.io:7233 --namespace example-prod.a1b2c --tls --api-key" "resolver should return without looping on self-referential env values"
207+
log "case passed: self-referential env values"
208+
200209
echo "PASS: temporalctx.plugin.zsh"

tests/uninstall_test.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ log "case passed: purge config"
5050
log "case: --full removes helper link"
5151
home3="$tmp_root/home3"
5252
custom3="$tmp_root/custom3"
53-
zshc3="$tmp_root/zshc3"
54-
mkdir -p "$home3" "$custom3" "$zshc3"
55-
PATH="$tmp_root/bin:$PATH" HOME="$home3" ZSH_CUSTOM="$custom3" ZSHC="$zshc3" "$REPO_ROOT/install.sh" --full >"$tmp_root/i3.out" 2>"$tmp_root/i3.err"
56-
[[ -L "$zshc3/temporal.zsh" ]] || fail "--full should create helper symlink"
57-
HOME="$home3" ZSH_CUSTOM="$custom3" ZSHC="$zshc3" "$REPO_ROOT/uninstall.sh" --full >"$tmp_root/u3.out" 2>"$tmp_root/u3.err"
58-
[[ ! -e "$zshc3/temporal.zsh" ]] || fail "--full uninstall should remove helper symlink"
53+
zsh_config3="$tmp_root/zsh_config3"
54+
mkdir -p "$home3" "$custom3" "$zsh_config3"
55+
PATH="$tmp_root/bin:$PATH" HOME="$home3" ZSH_CUSTOM="$custom3" ZSH_CONFIG="$zsh_config3" "$REPO_ROOT/install.sh" --full >"$tmp_root/i3.out" 2>"$tmp_root/i3.err"
56+
[[ -L "$zsh_config3/temporal.zsh" ]] || fail "--full should create helper symlink"
57+
HOME="$home3" ZSH_CUSTOM="$custom3" ZSH_CONFIG="$zsh_config3" "$REPO_ROOT/uninstall.sh" --full >"$tmp_root/u3.out" 2>"$tmp_root/u3.err"
58+
[[ ! -e "$zsh_config3/temporal.zsh" ]] || fail "--full uninstall should remove helper symlink"
5959
log "case passed: full helper removal"
6060

6161
echo "PASS: uninstall.sh"

uninstall.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ else
6565
echo "Plugin path not found: $target_dir"
6666
fi
6767

68-
zshc_dir="${ZSHC:-$HOME/.config/zsh}"
68+
zshc_dir="${ZSH_CONFIG:-${ZSH_CUSTOM:-${ZSH:-$HOME/.oh-my-zsh}/custom}}"
6969
helper_target="$zshc_dir/temporal.zsh"
7070
if [[ -L "$helper_target" ]]; then
7171
link_target="$(readlink "$helper_target" || true)"

0 commit comments

Comments
 (0)