diff options
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" |
