aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/plugin/bin/rotate-window
diff options
context:
space:
mode:
Diffstat (limited to 'tmuxrdr/plugin/bin/rotate-window')
-rwxr-xr-xtmuxrdr/plugin/bin/rotate-window34
1 files changed, 34 insertions, 0 deletions
diff --git a/tmuxrdr/plugin/bin/rotate-window b/tmuxrdr/plugin/bin/rotate-window
new file mode 100755
index 00000000..2457fa3b
--- /dev/null
+++ b/tmuxrdr/plugin/bin/rotate-window
@@ -0,0 +1,34 @@
+#!/bin/sh
+# tmux prefix+C-o (rotate-window, upward) and prefix+M-o (rotate-window -D):
+# every pane moves one place in pane-index order, wrapping. Measured on tmux
+# 3.7c: %0 %1 %2 becomes %1 %2 %0 upward, %2 %0 %1 downward, and focus stays on
+# the *position* -- the pane now there becomes current -- so this refocuses it
+# by id over the socket (pane.focus, which the CLI does not wrap).
+. "$(dirname "$0")/../lib.sh"
+
+p="$(active_pane)"
+panes="$(tab_panes "$p")"
+n="$(printf '%s\n' "$panes" | wc -l | tr -d ' ')"
+[ "$n" -gt 1 ] || exit 0
+pos="$(printf '%s\n' "$panes" | grep -n -x -F "$p" | cut -d: -f1)"
+
+# Swaps move panes, ids and all: swapping the first pane with each of the
+# others in turn rotates upward; the last with each, in reverse, downward.
+case "${1:-up}" in
+up)
+ first="$(printf '%s\n' "$panes" | sed -n 1p)"
+ printf '%s\n' "$panes" | sed 1d | while IFS= read -r t; do
+ swap "$first" "$t"
+ done
+ ;;
+down)
+ last="$(printf '%s\n' "$panes" | sed -n "${n}p")"
+ printf '%s\n' "$panes" | sed '$d' | sed -n '1!G;h;$p' | while IFS= read -r t; do
+ swap "$last" "$t"
+ done
+ ;;
+*)
+ fail "usage: rotate-window up|down"
+ ;;
+esac
+focus_pane "$(tab_panes "$p" | sed -n "${pos}p")"