#!/bin/sh # tmux prefix+. (command-prompt -T target { move-window -t "%%" }): move the # current window to index N. Herdr's tabs are positions -- tmux with # renumber-windows on -- so N is the place in the tab bar it moves to, where # tmux would refuse an index in use. Prompts for the target (run as a popup), # or takes N as its argument. Over the socket's tab.move, whose insert_index # counts slots in the list as it is before the move: moving right is one more. . "$(dirname "$0")/../lib.sh" n="${1:-}" if [ -z "$n" ]; then printf '(target) ' IFS= read -r n || exit 0 fi n="${n#:}" [ -n "$n" ] || exit 0 case "$n" in *[!0-9]*) fail "can't find window: $n" ;; esac p="$(active_pane)" ws="$(pane_info "$p" workspace_id)" tab="$(pane_info "$p" tab_id)" tabs="$(workspace_tabs "$ws" | cut -f1)" count="$(printf '%s\n' "$tabs" | wc -l | tr -d ' ')" [ "$n" -ge 1 ] && [ "$n" -le "$count" ] || fail "index $n out of range" from="$(printf '%s\n' "$tabs" | grep -n -x -F "$tab" | cut -d: -f1)" [ "$n" -eq "$from" ] && exit 0 if [ "$n" -gt "$from" ]; then at="$n" else at="$((n - 1))" fi api "{\"id\":\"tmux-mode\",\"method\":\"tab.move\",\"params\":{\"tab_id\":\"$tab\",\"insert_index\":$at}}" >/dev/null