Quantcast
Channel: User Kamil Maciorowski - Super User
Viewing all articles
Browse latest Browse all 675

Answer by Kamil Maciorowski for Tmux tile layout arranges 8 panes into 3x3 instead of 4x2

$
0
0

General approach

The select-layout tmux command allows you to specify a layout in the format used by window_layout or window_visible_layout tmux variable. This leads to the following solution:

  1. One-time preparation

    1. In a new tmux window manually create the layout you want.

    2. In a shell inside one of the panes in the tmux window query tmux for window_layout and save the response to a file:

      tmux display-message -p '#{window_layout}'>my_layout
  2. Usage

    Any time you want to use the layout, pass the content of the file to select-layout:

    tmux select-layout "$(cat my_layout)"

Notes:

  1. select-layout allows you to select a target pane (with -t target-pane), so you can use the command to select a layout for another window or even from the outside of tmux.

  2. Instead of a file you can use a shell variable, but since it's virtually impossible to change variables or the environment of an already running shell from the outside of the shell, and managing the environment in tmux is somewhat complicated, it's relatively easy to find yourself in a situation when you need the variable in a shell where it's not set. Files seem a better approach; e.g. you can create a directory ~/.tmux_layouts/ and store your custom layouts there.

  3. A layout created for N panes can be selected for a window containing up to N panes.

  4. A layout is saved from a window of certain dimensions. Selecting the layout for a window of different dimensions will make tmux recalculate it to the new dimensions. The result may or may not be exactly what you want, but at least the general arrangement of panes should match and you should be able to achieve the desired exact result by resizing the panes (e.g. by dragging their borders with your mouse).

  5. Layouts that look identical, may or may not be logically identical. E.g. the panes in this layout

    +-----+-----+|     |     ||     |     |+-----+-----+|     |     ||     |     |+-----+-----+

    can be resized either to

    +----+------+|    |      |+----++-----+|     |     ||     |     ||     |     |+-----+-----+

    or to

    +-------+---+|       |   ||       |   |+-------+   ||       +---+|       |   |+-------+---+

    In other words either the vertical or the horizontal border is a single entity that reaches from edge to edge, while the perpendicular border is in fact two borders that can be moved independently. Which exact layout you have, it depends on if you did the vertical or the horizontal split first while creating the layout. For more complicated layouts there are more possibilities.

    The differences manifest themselves not only when panes are resized. Visually identical but logically different layouts may give different results if selected for a window with fewer panes than in the layouts.

    In general you may want to carefully design your desired layout (I mean the order of splits), so it behaves as you expect when you resize panes (drag borders) or select it for a window with fewer panes.


Specific example

The following command arranges 8 panes to what I think the OP meant. When selected for a window with fewer panes, it may or may not match the expectation though.

tmux select-layout '0ab5,208x60,0,0[208x15,0,0{104x15,0,0,12,103x15,105,0,29},208x14,0,16{104x14,0,16,28,103x14,105,16,30},208x14,0,31{104x14,0,31,22,103x14,105,31,31},208x14,0,46{104x14,0,46,27,103x14,105,46,32}]'

While the general approach (above) advises saving to and reading from a file, this example specifies the layout directly. I created the "layout code" in tmux 3.3a.


Viewing all articles
Browse latest Browse all 675

Trending Articles