feat(tmux): add popup window switcher

This is a script that will popup a window with a list of windows in a
fzf promp. When selected the window will be focused. If the window is in
another session the session will also be switched and the window focused
This commit is contained in:
Ade Attwood 2022-12-22 19:52:56 +00:00
parent 3d387e4552
commit 6b8cc6b420
2 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,18 @@
#!/bin/bash
#
# Script taken from
# https://gist.github.com/thugcee/41d1ba786fa5e66167ed6ee45e4f6346
# customizable
LIST_DATA="#{window_name} #{session_name} #{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]}

View file

@ -36,6 +36,9 @@ bind > resize-pane -R 1
bind - resize-pane -D 1
bind + resize-pane -U 1
# Setup window switching via fzf
bind-key f run-shell -b ~/.local/bin/tmux-switch-pane
# bind : to command-prompt like vim
# this is the default in tmux already
bind : command-prompt