diff options
| author | Igor Soarez <igor@soarez.org> | 2026-10-05 11:27:00 +0300 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-10-05 11:27:00 +0300 |
| commit | 986e760687a2d34051934d410bec71fa2efc349b (patch) | |
| tree | f57dcc4ba0d7690fdf90eeb2f0970a8ebbefc45a /tmuxrdr/plugin/bin/swap-pane | |
| parent | 7b116c05bfda646af39d2524c54e70c751f57ee8 (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/swap-pane')
| -rwxr-xr-x | tmuxrdr/plugin/bin/swap-pane | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tmuxrdr/plugin/bin/swap-pane b/tmuxrdr/plugin/bin/swap-pane new file mode 100755 index 00000000..636c9904 --- /dev/null +++ b/tmuxrdr/plugin/bin/swap-pane @@ -0,0 +1,30 @@ +#!/bin/sh +# tmux prefix+{ / prefix+} (swap-pane -U / -D): swap the current pane with the +# previous / next one in pane-index order, wrapping; `marked` swaps with the +# pane prefix+m marked (swap-pane with no target, from the : prompt). The +# current pane keeps focus as it moves, as in tmux. +. "$(dirname "$0")/../lib.sh" + +p="$(active_pane)" +case "${1:-}" in +marked) + t="$(cat "$(state_dir)/marked" 2>/dev/null || true)" + [ -n "$t" ] && "$H" pane get "$t" >/dev/null 2>&1 || fail "no marked pane" + ;; +prev | next) + panes="$(tab_panes "$p")" + n="$(printf '%s\n' "$panes" | wc -l | tr -d ' ')" + [ "$n" -gt 1 ] || exit 0 + i="$(printf '%s\n' "$panes" | grep -n -x -F "$p" | cut -d: -f1)" + if [ "$1" = prev ]; then + j=$(( (i - 2 + n) % n + 1 )) + else + j=$(( i % n + 1 )) + fi + t="$(printf '%s\n' "$panes" | sed -n "${j}p")" + ;; +*) + fail "usage: swap-pane prev|next|marked" + ;; +esac +[ "$t" = "$p" ] || swap "$p" "$t" |
