17 April

Getting the current session name from tmux

Are you talking to me?

Had the little mystery of how to get the name of the current session in tmux into a shell script. Why? Because that script should talk to the same pane/window/session again later. Hacking and searching around a bit, this is what I came up with:

SESSION=`tmux list-panes -F '#{session_name}'`

Funny enough it uses the list-panes command, which by default lists only the panes of the current window and session. Then, using the -F format string, we can tell it to give us the session name only.

Later I can use this in the script like this:

tmux select-window -t$SESSION:window_name

... and there shouldn't be any mistakes as to which session I'm talking to.

Posted by betabug at 21:00 | Comments (1) | Trackbacks (0)
<< openbsd ipsec.conf roadwarrior puzzlestone | Main | Touchpad Synaptic Settings for Thinkpad L440 >>
Re: Getting the current session name from tmux

You could shorten that to:
SESSION=`tmux list-panes -F "#S"`

As of tmux 1.2 you can use also use:
SESSION=`tmux display-message -p "#S"`

Posted by: Matthew Musgrove at May 01,2012 03:40
Please send trackback to: http://betabug.ch/blogs/bsdcow/48/tbping
There are no trackbacks.
Leave a comment
Please note: Comments are moderated. Your comment will not show up until I can have a look at it and decide it's not SPAM. Sorry for the inconvenience.