Skip to content

Commit dba2d2e

Browse files
committed
Add optional --full install mode for opinionated helper aliases
1 parent 218664e commit dba2d2e

4 files changed

Lines changed: 89 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ To bypass wrapping for a command/session, set `TEMPORALCTX_DISABLE_WRAP=1`.
4646
./install.sh
4747
# or
4848
./install.sh ~/my-custom-zsh/plugins
49+
# or include opinionated tq/td/tl helpers in $ZSHC/temporal.zsh
50+
./install.sh --full
4951
```
5052

5153
Then add `temporalctx` to your `plugins=(...)` in `.zshrc`.
5254

55+
`--full` is optional and installs plugin-owned helper functions (`tq`, `td`, `tl`) by symlinking:
56+
- `${ZSHC:-~/.config/zsh}/temporal.zsh` -> `<plugin-dir>/temporalctx.full.zsh`
57+
5358
## Config format
5459

5560
```yaml

install.sh

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,37 @@ set -euo pipefail
44
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
55
REPO_DIR="$SCRIPT_DIR"
66

7-
if [[ $# -gt 1 ]]; then
8-
echo "Usage: ./install.sh [target-directory]" >&2
9-
exit 1
10-
fi
7+
usage() {
8+
echo "Usage: ./install.sh [--full] [target-directory]" >&2
9+
}
10+
11+
full_mode=0
12+
user_target=""
13+
while [[ $# -gt 0 ]]; do
14+
case "$1" in
15+
--full)
16+
full_mode=1
17+
shift
18+
;;
19+
-h|--help)
20+
usage
21+
exit 0
22+
;;
23+
--*)
24+
echo "Unknown option: $1" >&2
25+
usage
26+
exit 1
27+
;;
28+
*)
29+
if [[ -n "$user_target" ]]; then
30+
usage
31+
exit 1
32+
fi
33+
user_target="$1"
34+
shift
35+
;;
36+
esac
37+
done
1138

1239
if ! command -v temporal >/dev/null 2>&1; then
1340
echo "temporal CLI is required but was not found in PATH." >&2
@@ -16,8 +43,7 @@ if ! command -v temporal >/dev/null 2>&1; then
1643
fi
1744

1845
default_target_base="${ZSH_CUSTOM:-${ZSH:-$HOME/.oh-my-zsh}/custom}/plugins"
19-
if [[ $# -eq 1 ]]; then
20-
user_target="$1"
46+
if [[ -n "$user_target" ]]; then
2147
if [[ "$(basename "$user_target")" == "temporalctx" ]]; then
2248
target_dir="$user_target"
2349
else
@@ -73,6 +99,19 @@ else
7399
echo "Config already exists at $config_file"
74100
fi
75101

102+
if [[ "$full_mode" == "1" ]]; then
103+
zshc_dir="${ZSHC:-$HOME/.config/zsh}"
104+
helper_source="$target_dir/temporalctx.full.zsh"
105+
helper_target="$zshc_dir/temporal.zsh"
106+
mkdir -p "$zshc_dir"
107+
if [[ ! -f "$helper_source" ]]; then
108+
echo "Could not find opinionated helpers at $helper_source" >&2
109+
exit 1
110+
fi
111+
ln -sfn "$helper_source" "$helper_target"
112+
echo "Installed opinionated helpers at $helper_target"
113+
fi
114+
76115
echo
77116
echo "Installation complete."
78117
echo "Add temporalctx to your Oh My Zsh plugins list, for example:"

temporalctx.full.zsh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Opinionated Temporal helper aliases/functions.
2+
# Installed by `./install.sh --full`.
3+
4+
# Query a workflow's state.
5+
# Usage: tq <workflow-id>
6+
tq() {
7+
local wf_id="${1:?Usage: tq <workflow-id>}"
8+
temporal workflow query \
9+
--workflow-id "$wf_id" \
10+
--type getState
11+
}
12+
13+
# Describe a workflow.
14+
# Usage: td <workflow-id>
15+
td() {
16+
local wf_id="${1:?Usage: td <workflow-id>}"
17+
temporal workflow describe \
18+
--workflow-id "$wf_id"
19+
}
20+
21+
# List recent workflows.
22+
# Usage: tl [limit]
23+
tl() {
24+
local limit="${1:-10}"
25+
temporal workflow list \
26+
--limit "$limit"
27+
}

tests/install_test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,16 @@ 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"
49+
home3="$tmp_root/home3"
50+
zshc3="$tmp_root/zshc3"
51+
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")"
56+
assert_contains "$link_target" "temporalctx.full.zsh" "--full helper symlink should point to plugin helper file"
57+
log "case passed: --full helpers"
58+
4759
echo "PASS: install.sh"

0 commit comments

Comments
 (0)