Using multiple terminal x-windows with one tmux session

terminaltmux

I usually work with 2 monitors that are not quite vertically aligned (I have a benchtop power supply under my left monitor), but I want to have 4 terminal windows side-by side on my screens which I can cycle through easily, like so:

enter image description here

This arrangement makes me very sad because I can't easily cycle through all 4 in a sane way using only my keyboard (alt-tab doesn't cut it for me because it does not keep the "ordering" of all 4 windows – if I repeatedly press alt-tab, it just bounces between my 2 least-recently-used windows)

Is there a way to get tmux to generate a second x-window so that I can have 2 x-windows, with each one having 2 tmux panes inside of it?

Best Answer

tmux allows you to create "session groups" - multiple sessions that can all attach to the same set of windows.

(With thanks to https://gist.github.com/chakrit/5004006 :)

In the left terminal, create a new session+window group.

tmux new-session -s left

Split it into panes as usual.

:split-window -v

In the other (right-hand) terminal, connect to that existing window group. You're going to have to give it the old name to connect to, and its own session name to distinguish it.

tmux new-session -t left -s right

In that session, create another window and split

:new-window
:split-window -h

You can now see all the (tmux) windows in each (terminal) window, but the view in each is independent of the other.

To switch from one to the other (without using your window manager's own shortcuts), you could use eg. xdotool.

xdotool search --name 'left:0:' windowactivate
xdotool search --name 'right:1:' windowactivate

These assume that you have enabled tmux's set-titles option, in order to give the terminal a searchable name; and that you're only using one tmux window (set of panes) in each.

Related Question