

Tmux rename window windows#
It detects whether the destination window number is smaller than the smallest window number or bigger than the biggest window number, and if so, nudges all the other windows to the right or left (respectively) and re-numbers them to from 1 - N incrementally. None of the answers here satisfied me, so I wrote a script that (sort-of) mimicks the screen window-moving behavior for tmux. There doesn't seem to be a way around this.ĮDIT in 2020: Recent tmux versions require -d to keep the old behavior of moving the current window and staying with it in its new position. Thus, if you are on window #1, switch to window four and move it back one, you'll find that your last-used window is the new # 4 (formerly #3) instead of #1. The only issue I can find with this approach is that swap-window will implicitly alter the last-used window to the one you swapped with. By forcing a refresh of just the status bar (-S), you avoid this.
Tmux rename window update#
If you're wondering about refresh-client -S, that's necessary because sometimes, while the reordering from move-window will work properly, the status bar won't update until further changes are made. It works similarly when moving the first window to the end by picking a huge number you'll never use, it ensures that when move-window -r fires again everything will be numbered like you'd expect. This works by temporarily moving the last window to the unused index-0 and then calling move-window -r to renumber them starting from 1 again. If you are using base-index 1 like me and you don't think you'll ever go above 999 windows, you can use a little trick to make it roll properly, though the commands bloat a bit: set -g base-index 1īind-key -n M-Left run-shell 'if tmux list-windows | head -n 1 | grep -q active then tmux move-window -t 999 \ move-window -r \ refresh-client -S else tmux swap-window -d -t -1 fi'īind-key -n M-Right run-shell 'if tmux list-windows | tail -n 1 | grep -q active then tmux move-window -t 0 \ move-window -r \ refresh-client -S else tmux swap-window -d -t +1 fi' This can easily be combined with base-index and renumber-windows to have a list of windows that start at an arbitrary number and never has any gaps. So, the commands I use stop working when the window has reached the edge of the list: bind-key -n M-Left run-shell 'tmux list-windows | head -n 1 | grep -q active || tmux swap-window -d -t -1'īind-key -n M-Right run-shell 'tmux list-windows | tail -n 1 | grep -q active || tmux swap-window -d -t +1' I did this because, when you issue a swap +1 at the last window (or swap -1 at the first window), it will still swap, instead of looping back around again like you might expect: 0:one 1:two 2:three 3:zero* tmux.The approach I use combines a bit of Ashish's answer with piec's I have alt-left and right arrow bound to a quick little shell callout that moves the window one to the left or the right, unless it is the first or last window, respectfully. I've tried various configuration changes, but nothing seems to make a difference - the "name" is always (where X is the window index).Īm I doing something wrong, or is it a limitation of the server? In either case, is there some way to fix it? There's no automatic name-changes on the tmux status bar, and it won't respond to the scripts' name-changes (it does respond to some script changes, I'll have to work out why it isn't doing all of them). They recently moved the server to a new provider (Amazon AWS, I believe), and suddenly tmux is crippled. It's incredibly useful when you have to run a dozen processes at a time and see which ones are finished. On one of my clients' servers, I've been using the tmux status bar to monitor long-running processes, both through the automatic window-name changes and by setting window names through ANSI control codes in scripts.
