aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/plugin/bin/spread-layout
blob: 2b40de2aba696c8251996d79511066cca052b68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
# tmux prefix+E (select-layout -E): spread panes out evenly. tmux evens out the
# current pane and its neighbours; this evens every split in the tab -- each
# split's ratio becomes its share of the panes along that direction -- over
# the socket's layout.set_split_ratio, which keeps every pane running. herdr
# clamps ratios to 0.1-0.9, so past ten panes in a row they cannot be equal.
. "$(dirname "$0")/../lib.sh"

tab="$(pane_info "$(active_pane)" tab_id)"
api "{\"id\":\"tmux-mode\",\"method\":\"layout.export\",\"params\":{\"tab_id\":\"$tab\"}}" \
    | jq -c --arg tab "$tab" '
        def cells($d): if .type == "split" and .direction == $d
            then (.first | cells($d)) + (.second | cells($d)) else 1 end;
        def splits($p): if .type == "split" then
            .direction as $d
            | {path: $p, ratio: ((.first | cells($d)) / ((.first | cells($d)) + (.second | cells($d))))},
              (.first | splits($p + [false])),
              (.second | splits($p + [true]))
            else empty end;
        .result.layout.root | splits([])
        | {id: "tmux-mode", method: "layout.set_split_ratio",
           params: {tab_id: $tab, path: .path, ratio: .ratio}}' \
    | while IFS= read -r req; do
        api "$req" >/dev/null
    done