Use fzf to pick the agent in agent-cmd.sh

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.
This commit is contained in:
2026-04-28 13:59:38 +01:00
parent fdae4c140c
commit 1b87770f67
2 changed files with 31 additions and 23 deletions

View File

@@ -1,8 +1,28 @@
#!/usr/bin/env bash
# Wrapper that runs an agent command, then detaches if all panes in window are dead
# Detect available agents, prompt with fzf, run the selected one.
# Detaches the client if all panes in the window are dead afterwards.
# Run the agent command (don't use set -e, agent may exit non-zero)
"$@" || true
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