Updating window indexes with tmux?
Using tmux, I closed a window indexed 3, so now I have 1,2,4, ...
I'd rather have windows sequential, so is there any way to force them to re-index?
Solution 1:
tmux 1.7 includes the renumber-windows
session option that maintains a “gapless” sequence for a session’s window numbers. You can set the option “globally” to have it apply to all sessions that have not overridden the global value. E.g. in your ~/.tmux.conf
:
set-option -g renumber-windows on
If you do not always want all your sessions to have “gapless” window numbers, then you can use move-window -r
(the option is also new to *tmux 1.7) to renumber the windows in just the current session (or some other session if you use the -t
option).
Solution 2:
There's no builtin way to do it, but this bash script should work. Run it from within the session:
i=0
tmux list-windows | cut -d: -f1 | while read winindex; do
if (( winindex != i )); then
tmux move-window -d -s $winindex -t $i
fi
(( i++ ))
done
The -d
flag to move-window
avoids giving that window focus.