forked from hiroppy/tmux-agent-sidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhook.sh
More file actions
executable file
·43 lines (43 loc) · 1.94 KB
/
Copy pathhook.sh
File metadata and controls
executable file
·43 lines (43 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# Thin wrapper: delegates to the Rust binary. Called by Claude Code /
# Codex hooks (settings.json).
#
# Why this file exists even though `tmux-agent-sidebar setup` can emit
# absolute binary paths:
#
# 1. Late binding. settings.json only needs to know where `hook.sh`
# lives. The actual binary is resolved fresh on every hook fire, so
# the user can move or rebuild the binary (bin/ ↔ target/release/,
# relocate the plugin dir, swap install methods) without having to
# regenerate their agent config. Without this indirection, any
# setup-generated path becomes a stale snapshot the moment the
# binary moves.
#
# 2. Graceful absence. If the binary is missing — during a rebuild,
# mid-uninstall, or on a fresh clone before `cargo build` — this
# script exits 0 silently, so the agent session never sees a hook
# failure. A direct binary invocation would surface "no such file"
# errors into the user's workflow.
#
# Keep this wrapper small and side-effect-free. Any logic that needs to
# know event semantics belongs in the Rust `hook` subcommand.
PLUGIN_DIR="$(cd "$(dirname "$0")" && pwd -P)"
# Fallback location used when this script is executed from a Claude Code
# plugin install (e.g. `${CLAUDE_PLUGIN_ROOT}/hook.sh`). The plugin cache
# never contains the binary, so hop over to the tmux plugin directory
# where TPM placed it.
TPM_DIR="$HOME/.tmux/plugins/tmux-agent-sidebar"
if [ -x "$PLUGIN_DIR/bin/tmux-agent-sidebar" ]; then
BIN="$PLUGIN_DIR/bin/tmux-agent-sidebar"
elif [ -x "$PLUGIN_DIR/target/release/tmux-agent-sidebar" ]; then
BIN="$PLUGIN_DIR/target/release/tmux-agent-sidebar"
elif [ -x "$TPM_DIR/bin/tmux-agent-sidebar" ]; then
BIN="$TPM_DIR/bin/tmux-agent-sidebar"
elif [ -x "$TPM_DIR/target/release/tmux-agent-sidebar" ]; then
BIN="$TPM_DIR/target/release/tmux-agent-sidebar"
elif command -v tmux-agent-sidebar &>/dev/null; then
BIN="tmux-agent-sidebar"
else
exit 0
fi
exec "$BIN" hook "$@"