tmux and fzf: fuzzy tmux session/window/pane switcher

This script allows me to fuzzy search for window/pane using pane’s name – title – directory – command. Maybe someone will find it useful. It uses fzf-tmux for searching.

gist: https://gist.github.com/thugcee/41d1ba786fa5e66167ed6ee45e4f6346

#!/bin/bash

# customizable
LIST_DATA="#{window_name} #{pane_title} #{pane_current_path} #{pane_current_command}"
FZF_COMMAND="fzf-tmux -p --delimiter=: --with-nth 4 --color=hl:2"

# do not change
TARGET_SPEC="#{session_name}:#{window_id}:#{pane_id}:"

# select pane
LINE=$(tmux list-panes -a -F "$TARGET_SPEC $LIST_DATA" | $FZF_COMMAND) || exit 0
# split the result
args=(${LINE//:/ })
# activate session/window/pane
tmux select-pane -t ${args[2]} && tmux select-window -t ${args[1]} && tmux switch-client -t ${args[0]}

It can be started directly, but it’s better to use it from tmux. Put something like this into your tmux.conf to bind it to some key:

bind-key ` run-shell -b tmux-switch-pane.sh

Now you can use <tmux prefx> ` to display popup/split window with panes list, then fuzzy filter it, then select a needed pane and press <enter> to switch to it.

Option -p in fzf-tmux requires tmux 3.2 with popup windows. If you have older tmux then simply remove it.

Links to tools: