aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/plugin/bin/rotate-window
diff options
context:
space:
mode:
authorIgor Soarez <igor@soarez.org>2026-10-05 11:27:00 +0300
committerIgor Soarez <igor@soarez.org>2026-10-05 11:27:00 +0300
commit986e760687a2d34051934d410bec71fa2efc349b (patch)
treef57dcc4ba0d7690fdf90eeb2f0970a8ebbefc45a /tmuxrdr/plugin/bin/rotate-window
parent7b116c05bfda646af39d2524c54e70c751f57ee8 (diff)
tmuxrdr: tmux-mode plugin
The tmux default prefix bindings herdr has no built-in action for, as a herdr plugin built on its CLI and socket: break-pane, swap-pane and rotate-window by pane order (focus behaviour measured on tmux 3.7c), mark/clear-mark, last-window and switch-client -l (from focus events, per session), select-window and move-window by index, paste-buffer -p, display-message in tmux's default format, select-layout -E, kill-pane and kill-window behind tmux's y/n prompts, a command prompt taking tmux's commands, clock-mode, show-messages, and automatic-rename. Also a .gitignore for secrets scoped to tmuxrdr/, leaving herdr's own untouched.
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")"