#!/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