7

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?

Nifle
  • 34,203
  • 26
  • 108
  • 137
GerritS
  • 173
  • 1
  • 3

2 Answers2

12

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.

bartj3
  • 136
  • 1
  • 5
  • 1
    This is freaking amazing! – Trevor Hartman Mar 27 '17 at 16:41
  • 1
    please pardon my tmux nubeness.. but I'm not sure what to type to reach that point? this is what i have in my tmux.conf file: `set-option -g prefix C-a .. the above shortuct (ie bind C-j split-window..` so what do i type from a terminal to see this quick search thing? – abbood Jul 05 '18 at 07:50
  • @abbood I had the same problem, well you have to press your prefix key + ctrl j for it to open the search pane. For me prefix + c opens a new tmux window, so I changed the above to `bind j` and now I just press my prefix key + j and the search begins, sweet! – Kaka Ruto Nov 09 '21 at 11:19
0

@bartj3: Thanks. This is super cool!

Here is a slightly enhanced version (w/o sed and grep) for both switching sessions and windows:

bind j split-window -v "tmux list-sessions -F '#S' | fzf --reverse | xargs tmux switch-client -t"
bind k split-window -v "tmux list-window -F '#W' | fzf --reverse | xargs tmux select-window -t"

PROBLEM:

If you use the above while synchronize-panes is on, your search key-strokes will also type in the other panes.

QUESTION:

Does anyone have an idea on how to limit the key-strokes to the search-pane?

s3_
  • 13
  • 1
  • While this answer actually does appear to answer the question. The fact you submitted your own question, within the answer body, makes it impossible to answers your question. – Ramhound Jan 22 '19 at 21:49
  • Welcome to SuperUser! Your answer includes another question. Your question will get the appropriate attention if you post it as a new question. Please review site guidelines on [ask] and [answer]. Also, you will find that you will have a better experience if you take moment to take the Stack Overflow [tour]. If you follow the norms of the Stack Overflow community and approach it with an attitude of helping others too, it will serve you well. – Rey Juna Jan 22 '19 at 23:04
  • Ok. Posted as a new question in https://superuser.com/questions/1397211. Thanks. – s3_ Jan 22 '19 at 23:20