Tmux – Force Sessions to Sort Alphabetically

tmux

I thought that in tmux, the list of sessions (<prefix>-s) is always automatically sorted alphabetically. I seem to remember this being so always. I create my sessions with names specifically taylored to this assumption.

Lately, when I accidentally close a session and recreate it, it appears at the bottom of the list, which breaks muscle memory.

enter image description here

How can I configure tmux (version 3.1b) to sort sessions alphabetically?

Best Answer

Seems like tmux in versions <= 2.9a sorted sessions alphabetically, but starting from 3.1b this behavior changed. You can rebind <prefix>-s to whatever you like, in your case adding to ~/.tmux.conf following line should be sufficient:

bind s choose-tree -s -O name

From man tmux:

choose-tree [-GNrswZ] [-F format] [-f filter] [-O sort-order] [-t target-pane] [template]
     Put a pane into tree mode, where a session, window or pane may be chosen
     interactively from a list.  -s starts with sessions collapsed
     ...
     -O specifies the initial sort field: one of ‘index’, ‘name’, or ‘time’.