Compare commits
3 Commits
c40c2973a7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| df23247b07 | |||
| bcf2e92047 | |||
| 4649e0e7f7 |
34
agent-cmd.sh
34
agent-cmd.sh
@@ -6,18 +6,28 @@ agents=()
|
|||||||
command -v claude &>/dev/null && agents+=(claude)
|
command -v claude &>/dev/null && agents+=(claude)
|
||||||
command -v opencode &>/dev/null && agents+=(opencode)
|
command -v opencode &>/dev/null && agents+=(opencode)
|
||||||
command -v gemini &>/dev/null && agents+=(gemini)
|
command -v gemini &>/dev/null && agents+=(gemini)
|
||||||
command -v codex &>/dev/null && agents+=(gemini)
|
command -v codex &>/dev/null && agents+=(codex)
|
||||||
|
|
||||||
if [ ${#agents[@]} -eq 0 ]; then
|
if [ ${#agents[@]} -eq 0 ]; then
|
||||||
echo "No agent commands found (claude, opencode, gemini)"
|
echo "No agent commands found (claude, opencode, gemini)"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Minimize fzf prompt size while centering it.
|
||||||
|
width=24
|
||||||
|
height=$((${#agents[@]} + 6))
|
||||||
|
hmargin=$((($(tput cols) - width) / 2))
|
||||||
|
vpad=$((($(tput lines) - height) / 2))
|
||||||
|
[ $hmargin -lt 0 ] && hmargin=0
|
||||||
|
[ $vpad -lt 0 ] && vpad=0
|
||||||
|
tput cup "$vpad" 0
|
||||||
|
|
||||||
agent=$(printf '%s\n' "${agents[@]}" | fzf \
|
agent=$(printf '%s\n' "${agents[@]}" | fzf \
|
||||||
--prompt='agent> ' \
|
--prompt='agent> ' \
|
||||||
--reverse \
|
--reverse \
|
||||||
--border=rounded \
|
--border=rounded \
|
||||||
--margin=25%,30% \
|
--height="$height" \
|
||||||
|
--margin="0,$hmargin" \
|
||||||
--padding=1)
|
--padding=1)
|
||||||
|
|
||||||
if [ -n "$agent" ]; then
|
if [ -n "$agent" ]; then
|
||||||
@@ -27,9 +37,19 @@ fi
|
|||||||
# Brief delay to let tmux update pane status
|
# Brief delay to let tmux update pane status
|
||||||
sleep 0.1
|
sleep 0.1
|
||||||
|
|
||||||
# Count panes still running (pane_dead=0)
|
window_id=$(tmux display-message -p '#{window_id}')
|
||||||
# Note: our own pane counts as running since this script is executing
|
my_pane=$(tmux display-message -p '#{pane_id}')
|
||||||
running=$(tmux list-panes -F '#{pane_dead}' | grep -c '^0$' || true)
|
|
||||||
|
|
||||||
# If we're the only pane still running, all others are dead - detach
|
# Count live sibling panes (not us, not dead)
|
||||||
[ "$running" -le 1 ] && tmux detach-client
|
other_live=$(tmux list-panes -t "$window_id" -F '#{pane_id} #{pane_dead}' \
|
||||||
|
| awk -v me="$my_pane" '$1 != me && $2 == "0"' | wc -l | tr -d ' ')
|
||||||
|
|
||||||
|
if [ "$other_live" -eq 0 ]; then
|
||||||
|
# No live siblings — close the popup and kill the window
|
||||||
|
# (also cleans up any dead siblings).
|
||||||
|
tmux detach-client
|
||||||
|
tmux kill-window -t "$window_id" 2>/dev/null || true
|
||||||
|
else
|
||||||
|
# User has split off other live panes — only kill ours, keep popup open.
|
||||||
|
tmux kill-pane 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user