⚙️ Python API / wrapper for tmux
Repo tmux-python/libtmux, read from GitHub 12 min ago. tmux-python has not joined Take My Repo.
libtmux 0.67.1 fixes Session.new_window() with select_existing=True, which now finds a window by its literal name on every tmux and returns it instead of raising IndexError, and the format guide now says what a format can run.
select_existing=True finds a literal name on every tmux. libtmux now looks the window name up itself instead of relying on tmux's new-window -S, which matches a name differently per release: tmux 3.3a compared the escaped name, so a name containing #, %, , or } created a duplicate window, and tmux 3.7 and later expanded it a second time, so a name like #{session_name} could select another window. A Format name is expanded once against the session, then looked up. The existing window is returned and selected only with attach=True, and two windows with the name raise LibTmuxException. With window_index or target_window, tmux's -S still decides (#917).Format hands its text to tmux's format language, which runs #(...) as a shell command and expands an option's value again through E: and T:. The guide now says so, and that a plain str from a user passed to an argument tmux always expands, such as display_message, runs any #(...) it contains; Format.escape() shows such text exactly (#915).Two limits of the select_existing lookup: the lookup and the creation are separate tmux commands, so two callers can both create the window, and a name containing a backslash is not found once tmux stores it escaped (after rename_window, and for any new window from tmux 3.7).
See Literal text and tmux formats and the changelog for details.
Full Changelog: v0.67.0...v0.67.1
libtmux 0.67.0 keeps a # in session names, window names, pane titles, start directories and buffer paths as typed, where tmux used to expand it as a format, and adds Format to have tmux expand one value on purpose. Server.new_session() with kill_session=True kills only the exactly named session, and exact=True matches a session name exactly in kill_session(), switch_client() and attach_session().
# is literal in names, titles, start directories and buffer paths. rename_window("build#2") names the window build#2, and rename_window("#S") names it #S rather than the session's name. This covers new_session, new_window, rename_session, rename_window, set_title, split, new_pane, the respawn methods, display_popup's start directory and title, display_menu's title, the paths of save_buffer and load_buffer, and run_shell's cwd on tmux 3.8, the first release that expands it (#901, #910).Format opts one value into tmux's formats. pane.split(start_directory=Format("#{pane_current_path}")) opens a pane in the active pane's directory again. Each argument decides for itself, so one call can keep its name literal while expanding its start directory. +, join and Format.escape() add text from users or files and keep it literal, and adding plain text where tmux would read it as format syntax raises ValueError. Parameters that accept a format are typed str | Format, so a type checker flags a Format where tmux would store it as typed (#910).new_session(kill_session=True) kills only the exactly named session. Creating doom with kill_session=True no longer removes doomsday (#899).exact= for session names. kill_session, switch_client and attach_session accept exact=True to match a name exactly; without it they still match by prefix or pattern as tmux does, and warn when the name matched only that way (#899).To keep tmux's expansion where you relied on it:
from libtmux import Format pane.split(start_directory=Format("#{pane_current_path}")) window.rename_window(Format("#{pane_current_command}"))
See Literal text and tmux formats for which arguments are literal and how to opt in, and the changelog for the full list.
Full Changelog: v0.66.0...v0.67.0
libtmux 0.66.0 makes two narrow breaking changes: files Server.save_buffer() creates are readable by their owner only, and Pane.send_keys() with hex_keys=True no longer adds Enter. A socket path too long for tmux now raises SocketPathTooLong, saying how far over the limit it is and where the length came from.
save_buffer files. A new file Server.save_buffer() writes is readable and writable by its owner only. It used to follow the process umask, so saved scrollback and paste buffers were usually readable by every local user. A file that already exists keeps its permissions; call path.chmod(0o644) after saving to share a new one (#903).Pane.send_keys(..., hex_keys=True) sends only the bytes you give it, so an escape sequence or partial keystroke no longer runs the line. Pass enter=True to keep the old behaviour. Calls without hex_keys still send Enter by default, and enter=False and enter=None mean what they did (#904).SocketPathTooLong. A socket path too long for a UNIX socket raises SocketPathTooLong, a LibTmuxException, in place of tmux's bare File name too long. An explicit socket_path is checked when the Server is created and a socket_name when a command runs; Server.is_alive() still returns False instead of raising (#730).See the changelog for the full list.
Full Changelog: v0.65.0...v0.66.0
libtmux 0.65.0 adds a capability matrix to the compatibility page: which tmux release each gated feature needs, the methods it affects, and what libtmux does on an older tmux. It also raises the minimum tmux to 3.3a, the release's one breaking change; stay on libtmux 0.64.x to keep using tmux 3.2a.
run-shell working directory (tmux 3.4) to floating panes (tmux 3.7), with the Python methods each one affects and whether an older tmux warns and falls back or raises LibTmuxException. The matrix is generated from the same table the runtime gates read, and the repository publishes it as capabilities.json, keyed by capability ids shared with the other libtmux ports. The gates behave as before (#887).Server.server_access(), confirm_before(), command_prompt(), show_prompt_history(), clear_prompt_history() and Pane.display_popup() no longer check for tmux 3.3 before running (#888).See the changelog for the full list.
Full Changelog: v0.64.0...v0.65.0
libtmux 0.64.0 is a fixes-only release. Commands act on the session, window or pane they were called on, values that start with - or end in ; reach tmux as data, and a newline in a pane's path no longer breaks listings. There are no breaking changes, so it is a safe version to pin.
Window.select_pane(1) no longer changes another session's active pane (#896), and Session.kill_window("name") no longer kills a same-named window in another session (#897).-, such as rename_window("-n") or send_keys("-n hello"), is no longer read as a flag (#892, #893). A value ending in ; no longer runs the next argument as a tmux command: set_option("mouse;", "kill-server", global_=True) used to stop the server (#845).Server.panes and Server.windows raise ValueError for the whole server (#752).*** in place of environment values (#898).retry_until() improvements. It passes args= to the predicate and times its budget with a monotonic clock (#729).Other fixes: send_keys(hex_keys=True) sends every byte (#894), refresh() clears a field tmux has emptied (#895), repr(Server()) names the socket tmux actually uses (#727), import libtmux works when sys.stdout has no encoding (#890), and subclasses of the lookup exceptions type-check (#891).
See the changelog for the full list.
sys.stdout.encoding at import by @tony in #890retry_until's clock, and let it forward args by @tony in #729Full Changelog: v0.63.0...v0.64.0
libtmux 0.63.0 raises the minimum Python to 3.11 and brings the library in line with tmux 3.8. Pane.break_pane() now returns the destination window when it moves a window's only pane, and show_hook() reads the hooks tmux 3.8 added.
break_pane() returns the destination window (#879). Breaking out a window's only pane returns the destination Window, even if another client moved the pane first. On tmux 3.2a through 3.5 this could raise IndexError after the move had succeeded.show_hook() reads the hooks tmux 3.8 added, such as pane-created and window-zoomed, with their sparse indices intact. display_popup() needs a terminal client to run its command on tmux 3.8.Server, Session, Window and Pane class pages group their methods by job (finding one thing, listing everything, sending input) and say what each call returns and raises.See the changelog for the full list.
CONTRIBUTING.md + WRITING.md by @tony in #747test_capture_pane_flags[join_wrapped_numbers] by @tony in #655Full Changelog: v0.62.0...v0.63.0