feat(scripts): ✨ add kill command for tmux sessions
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
7eabb4fcff
commit
6eda3851a9
1 changed files with 58 additions and 0 deletions
58
bin/rclaude
58
bin/rclaude
|
|
@ -843,6 +843,63 @@ EOF
|
|||
[ "$_sent" -gt 0 ]
|
||||
}
|
||||
|
||||
cmd_kill() {
|
||||
# Kill live tmux sessions (ends the claude process inside). Mirrors
|
||||
# cmd_send's selector + local/remote dispatch. Used by supervisors
|
||||
# (clare web) to recycle stale orchestrator sessions.
|
||||
_sel=""; _pat=""; _yes=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--all) _sel=all; shift ;;
|
||||
--host) shift; _sel=host; _pat=${1:-}; shift ;;
|
||||
--host=*) _sel=host; _pat=${1#--host=}; shift ;;
|
||||
--match) shift; _sel=match; _pat=${1:-}; shift ;;
|
||||
--match=*) _sel=match; _pat=${1#--match=}; shift ;;
|
||||
--yes) _yes=1; shift ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
if [ -z "$_sel" ]; then
|
||||
cat >&2 <<'EOF'
|
||||
usage: rclaude kill (--all | --host <h> | --match <pat>) [--yes]
|
||||
Kills live claude-* tmux sessions (ends the claude process inside).
|
||||
--yes is required to actually kill (dry-run preview otherwise).
|
||||
EOF
|
||||
exit 2
|
||||
fi
|
||||
_rows=$(scan_hosts | while IFS= read -r _h; do list_tmux_on "$_h"; done \
|
||||
| filter_targets "$_sel" "$_pat")
|
||||
if [ -z "$_rows" ]; then
|
||||
echo "rclaude kill: no matching sessions" >&2
|
||||
exit 2
|
||||
fi
|
||||
echo "Targets:"
|
||||
printf '%s\n' "$_rows" | awk -F '\t' '{ printf " %-12s %s\n", $1, $3 }'
|
||||
if [ "$_yes" != 1 ]; then
|
||||
echo "(dry-run — pass --yes to kill)"
|
||||
exit 0
|
||||
fi
|
||||
_total=0; _failed=0
|
||||
_rowfile=$(mktemp /tmp/rclaude-kill.XXXXXX 2>/dev/null || echo /tmp/rclaude-kill.$$)
|
||||
printf '%s\n' "$_rows" > "$_rowfile"
|
||||
while IFS=$(printf '\t') read -r _host _kind _sess _detail; do
|
||||
[ -z "$_sess" ] && continue
|
||||
_total=$((_total + 1))
|
||||
if is_local "$_host"; then
|
||||
tmux kill-session -t "$_sess" 2>/dev/null || _failed=$((_failed + 1))
|
||||
else
|
||||
_q_sess=$(sh_quote "$_sess")
|
||||
ssh -o BatchMode=yes -o ConnectTimeout=3 "$_host" \
|
||||
"tmux kill-session -t $_q_sess" </dev/null >/dev/null 2>&1 \
|
||||
|| _failed=$((_failed + 1))
|
||||
fi
|
||||
done < "$_rowfile"
|
||||
rm -f "$_rowfile"
|
||||
_killed=$((_total - _failed))
|
||||
echo "Killed $_killed of $_total session(s)."
|
||||
[ "$_killed" -gt 0 ]
|
||||
}
|
||||
|
||||
# Resume strategy:
|
||||
# - 1 match → attach directly
|
||||
# - 2+ matches → single-key picker (1-9 then a-z, max 35)
|
||||
|
|
@ -1410,6 +1467,7 @@ case ${1:-} in
|
|||
resume) shift; cmd_resume "$@"; exit ;;
|
||||
triage) shift; cmd_triage "$@"; exit ;;
|
||||
send) shift; cmd_send "$@"; exit ;;
|
||||
kill) shift; cmd_kill "$@"; exit ;;
|
||||
setup|install) shift; cmd_setup "$@"; exit ;;
|
||||
voice) shift; cmd_voice "$@"; exit ;;
|
||||
-v|--version) cmd_version; exit ;;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue