blob: 636c9904e5c6c73e7718f3bd53dc510dcdf5bb3a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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"
|