Tmux – Interactive Search of Sessions

bsdcommand linecommand-line-toollinuxtmux

When switching between tmux sessions with the interactive session menu (<prefix>-s), you can jump to a specific session by typing the session's numeric or alphabetical index, e.g.

(0) + first_session: 1 windows
(1) + second_session: 2 windows
(2) + third_session: 1 windows
(3) + secret_session: 1 windows

Pressing 1 will open up the second_session session.

I often have >20 tmux sessions open and I'd like to have a way to search without looking at the whole list. Is there a way to change the behaviour to have an interactive search? That is, I would like to type sec and have the list narrow to

(1) + second_session: 2 windows
(3) + secret_session: 1 windows

I've googled quite a bit and found nothing; is this behaviour possible?

Best Answer

Yes it is, but as far as i know you'll need an extra tool for the searching itself. I'm using fzf for the (fuzzy) searching. Once fzf is installed you can use the following config to set up the session switching with search:

bind C-j split-window -v "tmux list-sessions | sed -E 's/:.*$//' | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | xargs tmux switch-client -t"

I didn't figure this out myself but took this from Chris Toomey's public tmux conf.