Skip to content

Instantly share code, notes, and snippets.

@seik0ixtem
Forked from jordansissel/README.md
Last active February 28, 2018 11:45
Show Gist options
  • Save seik0ixtem/a9e516b981c922281b0de8a4e20ff01e to your computer and use it in GitHub Desktop.
Save seik0ixtem/a9e516b981c922281b0de8a4e20ff01e to your computer and use it in GitHub Desktop.
Sorting windows in tmux by hostname.

Sorts tmux windows by name. (For improved names I use ssh alias in bash: https://github.com/seik0ixtem/myconfs/blob/master/.bashrc , which leaves much to be improved, though. Some people prefere patched tmux distributions, check this fork source.)

I added -d options to tmux move-window to prevent on-screen jumping.

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 -d -s "$1" -t 100"$1)}'
# sort and move windows
tmux list-windows | sort -sk2 \
| awk -F: '{system("tmux move-window -d -s "$1" -t "(NR - 1))}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment