Move agent discovery out of `agent.sh` so the picker runs on every new pane, including manual splits. Set the agent session's default-command to agent-cmd.sh and re-apply session options on every invocation so changes propagate to live sessions.
36 lines
1015 B
Bash
Executable File
36 lines
1015 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Detect available agents, prompt with fzf, run the selected one.
|
|
# Detaches the client if all panes in the window are dead afterwards.
|
|
|
|
agents=()
|
|
command -v claude &>/dev/null && agents+=(claude)
|
|
command -v opencode &>/dev/null && agents+=(opencode)
|
|
command -v gemini &>/dev/null && agents+=(gemini)
|
|
command -v codex &>/dev/null && agents+=(gemini)
|
|
|
|
if [ ${#agents[@]} -eq 0 ]; then
|
|
echo "No agent commands found (claude, opencode, gemini)"
|
|
exit 1
|
|
fi
|
|
|
|
agent=$(printf '%s\n' "${agents[@]}" | fzf \
|
|
--prompt='agent> ' \
|
|
--reverse \
|
|
--border=rounded \
|
|
--margin=25%,30% \
|
|
--padding=1)
|
|
|
|
if [ -n "$agent" ]; then
|
|
"$agent" || true
|
|
fi
|
|
|
|
# Brief delay to let tmux update pane status
|
|
sleep 0.1
|
|
|
|
# Count panes still running (pane_dead=0)
|
|
# Note: our own pane counts as running since this script is executing
|
|
running=$(tmux list-panes -F '#{pane_dead}' | grep -c '^0$' || true)
|
|
|
|
# If we're the only pane still running, all others are dead - detach
|
|
[ "$running" -le 1 ] && tmux detach-client
|