aboutsummaryrefslogtreecommitdiff
path: root/tmuxrdr/plugin/bin/select-window
blob: 691d7c9f60d69cff802d86effc1c08b1ef2c7c9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# tmux prefix+0 and prefix+' (select-window -t :=N). Herdr numbers tabs by
# their place in the tab bar, from 1 -- like tmux with base-index 1 and
# renumber-windows on -- so N is a position: 0 finds nothing, exactly as
# prefix+0 does under this machine's base-index 1. With no argument it prompts
# for the index, as prefix+' does (run as a popup).
. "$(dirname "$0")/../lib.sh"

n="${1:-}"
if [ -z "$n" ]; then
    printf '(index) '
    IFS= read -r n || exit 0
fi
[ -n "$n" ] || exit 0
case "$n" in
    *[!0-9]*) fail "can't find window: $n" ;;
esac

ws="$(pane_info "$(active_pane)" workspace_id)"
tab="$(workspace_tabs "$ws" | sed -n "${n}p" | cut -f1)"
[ "$n" -gt 0 ] && [ -n "$tab" ] || fail "can't find window: $n"
"$H" tab focus "$tab" >/dev/null