santree 0.2.15 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,45 @@
1
- # Santree Shell Integration for Zsh
2
- # ==================================
1
+ # Santree Shell Integration for Zsh — self-caching bootstrap
2
+ # ===========================================================
3
3
  #
4
- # This script provides a shell wrapper around the santree CLI to enable:
5
- # 1. Automatic directory switching after `worktree create` and `worktree switch` commands
6
- # 2. Automatic recovery when the current worktree directory is deleted
4
+ # This output is produced by `santree helpers shell-init zsh`. The santree CLI
5
+ # cold-starts in several seconds (Node + Pastel), so eval'ing it on every shell
6
+ # launch is too slow. To avoid that, the bootstrap below writes the rendered
7
+ # integration body to a cache file once, then sources the cache. Subsequent
8
+ # shells can source the cache file directly — bypassing the santree CLI
9
+ # entirely — and the cache self-invalidates whenever the santree binary is
10
+ # upgraded (see the self-validation header at the top of the cache content).
7
11
  #
8
- # Installation:
9
- # Add to your .zshrc: eval "$(santree helpers shell-init zsh)"
12
+ # .zshrc usage (one-liner with first-run fallback):
13
+ # _SI=${XDG_CACHE_HOME:-$HOME/.cache}/santree/init-zsh.zsh
14
+ # [[ -f $_SI ]] && source $_SI || eval "$(santree helpers shell-init zsh)"
10
15
  #
11
- # How it works:
12
- # -------------
13
- # Since child processes cannot change the parent shell's directory, the CLI
14
- # outputs special markers (SANTREE_CD:path) that this wrapper intercepts
15
- # to perform the actual `cd` command in the current shell.
16
+ # Behavior:
17
+ # - First shell after install: cache miss → runs santree (slow), writes cache.
18
+ # - Subsequent shells: source cache directly (fast, no santree spawn).
19
+ # - After `npm i -g santree` upgrade: cache mtime older than new binary,
20
+ # self-validation triggers a one-time regeneration in that shell.
21
+
22
+ _santree_cache="${SANTREE_CACHE_DIR:-${XDG_CACHE_HOME:-$HOME/.cache}/santree}/init-zsh.zsh"
23
+ mkdir -p "${_santree_cache:h}"
24
+
25
+ # Write the integration body to the cache file. Single-quoted heredoc
26
+ # delimiter ('SANTREE_INIT_BODY_EOF__') prevents parameter expansion of the
27
+ # body — the variables and functions are evaluated only when the cache file
28
+ # is sourced, not during this write.
29
+ cat > "$_santree_cache" <<'SANTREE_INIT_BODY_EOF__'
30
+ # Santree Shell Integration for Zsh
31
+ # ==================================
32
+ # AUTO-GENERATED CACHE — do not edit. Regenerate with:
33
+ # eval "$(santree helpers shell-init zsh)"
16
34
  #
17
- # The wrapper also handles the case where you're in a worktree directory
18
- # that gets deleted (e.g., after `santree worktree clean` or `santree worktree remove`),
19
- # automatically returning you to the main repository or home directory.
35
+ # Self-validation: if the santree binary on $PATH is newer than this cache
36
+ # file, fall back to the slow path: re-run santree, which overwrites this
37
+ # cache and re-sources the fresh integration. `return` short-circuits the
38
+ # (now-stale) body below so its definitions don't get loaded.
39
+ if [[ ${commands[santree]:-} -nt ${(%):-%x} ]]; then
40
+ eval "$(command santree helpers shell-init zsh)"
41
+ return
42
+ fi
20
43
 
21
44
  # Export marker so `santree doctor` can verify shell integration is loaded
22
45
  export SANTREE_SHELL_INTEGRATION=1
@@ -172,3 +195,10 @@ if (( $+functions[compdef] )); then
172
195
  compdef _santree santree
173
196
  compdef _santree st
174
197
  fi
198
+ SANTREE_INIT_BODY_EOF__
199
+
200
+ # Source the cache we just wrote so this shell gets the integration immediately.
201
+ # Future shells can skip the santree CLI and source the cache directly via the
202
+ # .zshrc one-liner shown in the comment block at the top of this output.
203
+ source "$_santree_cache"
204
+ unset _santree_cache