aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/plugin/bin/spread-layout
diff options
context:
space:
mode:
Diffstat (limited to 'tmuxrdr/plugin/bin/spread-layout')
-rwxr-xr-xtmuxrdr/plugin/bin/spread-layout25
1 files changed, 25 insertions, 0 deletions
diff --git a/tmuxrdr/plugin/bin/spread-layout b/tmuxrdr/plugin/bin/spread-layout
new file mode 100755
index 00000000..2b40de2a
--- /dev/null
+++ b/tmuxrdr/plugin/bin/spread-layout
@@ -0,0 +1,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