Add agent-cmd.sh wrapper that detaches the client when all panes in the current window have exited. This allows multiple agent windows (one per directory) while automatically returning to the shell when done with a particular window's agents. - remain-on-exit keeps panes alive after agent exits to check status - Wrapper counts running panes and detaches when it's the last one
16 lines
537 B
Bash
Executable File
16 lines
537 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Wrapper that runs an agent command, then detaches if all panes in window are dead
|
|
|
|
# Run the agent command (don't use set -e, agent may exit non-zero)
|
|
"$@" || true
|
|
|
|
# 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
|