Feature request: Clean up
Using tmux with Python means we lose the ability to interact with tmux. libtmux is a great tool, though currently my biggest worry is that I create a bunch of sessions, windows and panes.
Exiting out of panes is easy, since if you do && exit at the end of the command you execute it closes that terminal and hence closes that pane.
However, I find that there is no easy way to close windows or sessions. Im currently contemplating writing my own script with some simple logic like...
if does_window_contain_pane(window-number) == False:
tmux kill-window -t window-number
if session_contains_windows(sesh) == False:
tmux kill-session -t sesh
Think this is possible to implement? I have noticed a lot of scripts floating around trying to accomplish this. It would make libtmux all the more powerful and all the helper scripts obsolete.
Thanks for the great tool!!
Server, Session, Window, and Pane now provide .kill() methods and with context managers for automatic teardown (borrowed-server exit safety and create-or-reuse ownership are tracked in #724 and #804).
- Context managers (v0.44.0, 2025-02-16): Context managers guide
.kill()methods (v0.28.0, 2024-02-14 and v0.30.0, 2024-02-16):Session.kill()reference,Window.kill()reference,Pane.kill()reference