DEV Community

Play Button Pause Button
Waylon Walker
Waylon Walker

Posted on • Originally published at waylonwalker.com

Jump to running tmux sessions with fzf

Quickly getting between tmux splits is critical skill for productivity. You
can get by with next or prev session for awhile, but if you have more than
about three session you need something a bit more targeted.

Full Screen selector

I have used this fzf one keybinding for quite awhile, honestly I did not make
it up, and cannot remember where it came from. It will open up a session picker
in a new full screen window.


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


Enter fullscreen mode Exit fullscreen mode

Popup selector

Like with many of my keybindings I have swapped this one out for a popup
version. It just feels so smooth.


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


Enter fullscreen mode Exit fullscreen mode

Be sure to check out the full YouTube playlist and subscribe if you like it.

tmux playlist on youtub

Also check out this long form post for more about how I use tmux.

Top comments (4)

Collapse
 
macintacos profile image
Julian Torres

Hiya! I noticed that trying to escape from the popup still ends up selecting the session that was highlighted. How can you set it up such that esc or C-c just dismisses the popup and doesn't do anything?

Collapse
 
destynova profile image
Oisín

One thing to note: the display-popup command was only introduced in the latest release of tmux, version 3.2. At this time, some distros still have 3.1c in the package repos (for example, Ubuntu 21.04), so tmux needs to be built from source. Worth it though.

Collapse
 
y1450 profile image
y1450

Then session listed in fzf preview are sorted by name, there is snippet that show them by last visited order.

bind -n M-j display-popup -E "\
    tmux list-sessions -F '#{?session_attached,,#{session_activity},#{session_name}}' |\
    sort -r |\
    sed '/^$/d' |\
    cut -d',' -f2- \|
    fzf --reverse --header jump-to-session --preview 'tmux capture-pane -pt {}'  |\
    xargs tmux switch-client -t"
Enter fullscreen mode Exit fullscreen mode
Collapse
 
jrop profile image
Jonathan Apodaca

This is nice. Adopted.