Tmux socket api

sockettmuxunix-sockets

Is there any way I can control a tmux server and send commands to it like switching to a specific window in a session, or make some queries about the panes through the socket it creates?

I've looked into libtmux for python and it appears to be lacking in some ways. Is there an official reference for the tmux api where I could look? The official tmux package on my distro contains only a single tmux binary.

Is there any way other than reading the source to find out how one can control tmux through its socket?
Are there any other terminal multiplexers which make it easy/ are intended to make it easy?

Best Answer

It is not difficult to do the tasks you ask using python-tmux.

E.g. if you start a new server with session name foo

tmux new-session -s foo

you can attach to it via python tmux (assuming the python library is installed) from ipython via

import libtmux
server = libtmux.Server()
session = server.find_where({ "session_name": "foo" })

Then you can watch in your tmux window the action of commands e.g.

session.cmd("send-keys","x")

will send a keystroke "x". The pane list you asked for can be queried via

session.cmd("list-panes").stdout

and you can switch to a specific window (say nr. 1) with

session.cmd("select-window","-t","1").stdout

You do not have to read the source code of tmux to learn this. All these commands are documented in the man page of tmux. If this is not sufficient for you, you need to be more specific what you mean by python-libtmux being "lacking in some way".

Related Question