Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ An oh-my-zsh plugin for switching Temporal contexts (`~/.temporal/config`) simil
- `temporalctx <name>`: switch to named context
- `temporalctx -`: switch to previous context
- `temporalctx -c`: print current context
- `temporalctx edit` (`-e`/`--edit`): open config in `$VISUAL`, then `$EDITOR`, else `vi`
- `temporal ...`: wrapped by plugin to automatically include current context flags

## Helper function
Expand Down
10 changes: 10 additions & 0 deletions temporalctx.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ _temporalctx_pick_context() {
_temporalctx_switch "$selected"
}

_temporalctx_edit_config() {
local config_file editor_cmd
config_file="$(_temporalctx_config_file)"
editor_cmd="${VISUAL:-${EDITOR:-vi}}"
${=editor_cmd} "$config_file"
}

typeset -ga _temporalctx_flags

_temporalctx_build_flags() {
Expand Down Expand Up @@ -270,6 +277,9 @@ temporalctx() {
"")
_temporalctx_pick_context
;;
edit|-e|--edit)
_temporalctx_edit_config
;;
-c)
_temporalctx_current_context
;;
Expand Down
24 changes: 24 additions & 0 deletions tests/temporalctx_plugin_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ assert_contains "$out" "pick=cloud-prod" "interactive picker should switch to fz
assert_contains "$out" "curr=cloud-prod" "current context should match picker result"
log "case passed: interactive picker"

# Test: edit subcommand opens config in VISUAL/EDITOR.
log "case: edit subcommand opens config with VISUAL/EDITOR"
cat > "$tmp_root/bin/editor-visual" <<'SH'
#!/usr/bin/env bash
printf '%s\n' "$*" > "${TMP_EDITOR_VISUAL_LOG:?}"
SH
cat > "$tmp_root/bin/editor-fallback" <<'SH'
#!/usr/bin/env bash
printf '%s\n' "$*" > "${TMP_EDITOR_FALLBACK_LOG:?}"
SH
chmod +x "$tmp_root/bin/editor-visual" "$tmp_root/bin/editor-fallback"

visual_log="$tmp_root/visual.log"
fallback_log="$tmp_root/fallback.log"
PATH="$tmp_root/bin:$PATH" TEMPORAL_CONFIG="$cfg" VISUAL="$tmp_root/bin/editor-visual" EDITOR="$tmp_root/bin/editor-fallback" TMP_EDITOR_VISUAL_LOG="$visual_log" TMP_EDITOR_FALLBACK_LOG="$fallback_log" zsh -c '
source "'$REPO_ROOT'/temporalctx.plugin.zsh"
temporalctx edit
'
[[ -f "$visual_log" ]] || fail "VISUAL editor should be invoked by edit subcommand"
visual_args="$(cat "$visual_log")"
assert_contains "$visual_args" "$cfg" "editor should receive config file path"
[[ ! -f "$fallback_log" ]] || fail "EDITOR fallback should not run when VISUAL is set"
log "case passed: edit subcommand"

# Test: temporal command wrapping + opt-out.
log "case: temporal wrapper injects flags and supports opt-out"
out="$(PATH="$tmp_root/bin:$PATH" TEMPORAL_CONFIG="$cfg" TEMPORAL_CLOUD_PROD_API_KEY=sekret zsh -c '
Expand Down