tmux socket api

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












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?







share|improve this question






















  • Not asked for, but for reference: The tmux source code is available at github.com/tmux/tmux
    – Kusalananda
    Apr 16 at 9:59















up vote
2
down vote

favorite












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?







share|improve this question






















  • Not asked for, but for reference: The tmux source code is available at github.com/tmux/tmux
    – Kusalananda
    Apr 16 at 9:59













up vote
2
down vote

favorite









up vote
2
down vote

favorite











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?







share|improve this question














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?









share|improve this question













share|improve this question




share|improve this question








edited Apr 16 at 9:55

























asked Apr 10 at 13:00









saga

869119




869119











  • Not asked for, but for reference: The tmux source code is available at github.com/tmux/tmux
    – Kusalananda
    Apr 16 at 9:59

















  • Not asked for, but for reference: The tmux source code is available at github.com/tmux/tmux
    – Kusalananda
    Apr 16 at 9:59
















Not asked for, but for reference: The tmux source code is available at github.com/tmux/tmux
– Kusalananda
Apr 16 at 9:59





Not asked for, but for reference: The tmux source code is available at github.com/tmux/tmux
– Kusalananda
Apr 16 at 9:59











1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted
+50










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".






share|improve this answer






















  • How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
    – saga
    Apr 16 at 10:48











  • The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
    – saga
    Apr 16 at 10:53







  • 1




    Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
    – alphanum
    Apr 16 at 11:28











  • Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
    – alphanum
    Apr 16 at 11:40











  • I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
    – alphanum
    Apr 23 at 14:09











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436772%2ftmux-socket-api%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted
+50










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".






share|improve this answer






















  • How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
    – saga
    Apr 16 at 10:48











  • The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
    – saga
    Apr 16 at 10:53







  • 1




    Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
    – alphanum
    Apr 16 at 11:28











  • Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
    – alphanum
    Apr 16 at 11:40











  • I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
    – alphanum
    Apr 23 at 14:09















up vote
3
down vote



accepted
+50










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".






share|improve this answer






















  • How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
    – saga
    Apr 16 at 10:48











  • The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
    – saga
    Apr 16 at 10:53







  • 1




    Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
    – alphanum
    Apr 16 at 11:28











  • Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
    – alphanum
    Apr 16 at 11:40











  • I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
    – alphanum
    Apr 23 at 14:09













up vote
3
down vote



accepted
+50







up vote
3
down vote



accepted
+50




+50




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".






share|improve this 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".







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 16 at 10:34

























answered Apr 16 at 10:27









alphanum

1594




1594











  • How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
    – saga
    Apr 16 at 10:48











  • The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
    – saga
    Apr 16 at 10:53







  • 1




    Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
    – alphanum
    Apr 16 at 11:28











  • Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
    – alphanum
    Apr 16 at 11:40











  • I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
    – alphanum
    Apr 23 at 14:09

















  • How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
    – saga
    Apr 16 at 10:48











  • The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
    – saga
    Apr 16 at 10:53







  • 1




    Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
    – alphanum
    Apr 16 at 11:28











  • Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
    – alphanum
    Apr 16 at 11:40











  • I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
    – alphanum
    Apr 23 at 14:09
















How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
– saga
Apr 16 at 10:48





How do I send control characters? According to tmux man page C- will be interpreted as ctrl. libtmux passes it as a literal.
– saga
Apr 16 at 10:48













The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
– saga
Apr 16 at 10:53





The point I was trying to make is that I couldn't find the api to talk to a tmux server anywhere on the net. It also suggests that tmux wasn't supposed to be scriptable.
– saga
Apr 16 at 10:53





1




1




Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
– alphanum
Apr 16 at 11:28





Man page: "if the string is not recognised as a key, it is sent as a series of characters". That is, session.cmd("send-keys","C-a","x") will send Ctrl-a, x, whereas session.cmd("send-keys","C-ax") will send C, -, a, x. Also note that you cannot use C-b to send the prefix key to tmux, it will be received by the app inside the terminal.
– alphanum
Apr 16 at 11:28













Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
– alphanum
Apr 16 at 11:40





Apparently also the python bindings talk to tmux only via the binary. Presumably the socket api is not indended to be used by other programs. I would try to ask about this on the tmux mailing list groups.google.com/forum/#!forum/tmux-users
– alphanum
Apr 16 at 11:40













I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
– alphanum
Apr 23 at 14:09





I still have a comment on the part about controlling tmux directly through its socket. Presumably the best way to achieve this would be to refactor tmux into a official library/API+program structure. This would necessitate developers to keep the bindings up to date (and hopefully stable). If you were to start implementing your own custom bindings from studying the source code you might run into having to deal with changes in tmux internal protocols on a regular basis. Perhaps the official developers are open to discussions on this, if say, it may be required for performance reasons,etc.
– alphanum
Apr 23 at 14:09













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f436772%2ftmux-socket-api%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?