Skip to content

Instantly share code, notes, and snippets.

@wwalker
Forked from jordansissel/README.md
Created May 2, 2016 18:04
Show Gist options
  • Save wwalker/ed2d504c85a536a902e9a5780e195537 to your computer and use it in GitHub Desktop.
Save wwalker/ed2d504c85a536a902e9a5780e195537 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))}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment