Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created July 6, 2011 05:04
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jordansissel/1066602 to your computer and use it in GitHub Desktop.
Save jordansissel/1066602 to your computer and use it in GitHub Desktop.
Sorting windows in tmux by hostname.

For this to work, it requires my tmux fork that includes what I use as the hostname in the window list.

At any rate, it'll sort my tmux sessions alphabetically by the host I'm using.

my tmux fork: https://github.com/jordansissel/tmux

Starts with:

(0) -    nightfall: zsh - /home/jls/projects/tmux/trunk                                                            
(1)        carrera: screen -x irc                                                                                  
(2)        carrera: zsh - /home/jls                                                                                
(3) *          ops: zsh - /home/jls                                                                                
(4)      nightfall: zsh - /home/jls/projects/tmux/trunk                                                            

After sorting:

(0)        carrera: screen -x  irc                                                                                  
(1)        carrera: zsh - /home/jls                                                                                
(2)      nightfall: zsh - /home/jls/projects/tmux/trunk                                                            
(3) -    nightfall: zsh - /home/jls/projects/tmux/trunk                                                            
(4) *          ops: zsh - /home/jls                                                                                
#!/bin/sh
# Shift current ids far out
tmux list-windows | awk -F: '{system("tmux move-window -s "$1" -t 100"$1)}'
# sort and move windows
tmux list-windows | sort -sk2 \
| awk -F: '{system("tmux move-window -s "$1" -t "(NR - 1))}'
@seik0ixtem
Copy link

You can add -d option to move-window to prevent focus jumping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment