From 6b8cc6b42058dd4a9387872784c071651b5c1f7c Mon Sep 17 00:00:00 2001 From: Ade Attwood Date: Thu, 22 Dec 2022 19:52:56 +0000 Subject: [PATCH] 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 --- site-modules/core/files/bin/tmux-switch-pane | 18 ++++++++++++++++++ site-modules/core/files/tmux.conf | 3 +++ 2 files changed, 21 insertions(+) create mode 100755 site-modules/core/files/bin/tmux-switch-pane diff --git a/site-modules/core/files/bin/tmux-switch-pane b/site-modules/core/files/bin/tmux-switch-pane new file mode 100755 index 0000000..3d6b327 --- /dev/null +++ b/site-modules/core/files/bin/tmux-switch-pane @@ -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]} diff --git a/site-modules/core/files/tmux.conf b/site-modules/core/files/tmux.conf index d068c57..713b77d 100644 --- a/site-modules/core/files/tmux.conf +++ b/site-modules/core/files/tmux.conf @@ -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