From 383a900c2d6584b61a57dd38f416bde7e532382f Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 6 Oct 2025 13:57:09 +0200 Subject: [PATCH] feat(tmuxinator): show popup for choosing session on s --- tmux/bin/fuzzy-switch.sh | 40 ++++++++++++++++++++++++++++++++++++++++ tmux/tmux.conf | 2 ++ 2 files changed, 42 insertions(+) create mode 100755 tmux/bin/fuzzy-switch.sh diff --git a/tmux/bin/fuzzy-switch.sh b/tmux/bin/fuzzy-switch.sh new file mode 100755 index 0000000..5b66e7e --- /dev/null +++ b/tmux/bin/fuzzy-switch.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash +die() { + printf "\n[tmux-fuzzy] %s\n" "$1" >&2 + # keep popup visible if we're in a popup + if [ -n "${TMUX:-}" ]; then + printf "Press ENTER to close..." + read -r _ || true + fi + exit 1 +} + +list_projects() { + tmuxinator list 2>/dev/null \ + | sed '1{/tmuxinator projects:/d;}' \ + | tr -s '[:space:]' '\n' \ + | grep -E '^[[:alnum:]_.:-]+$' \ + || true +} + +# unique + sorted +items="$(list_projects | sort -u)" +[ -n "$items" ] || die "No tmuxinator projects found." + +sel="$( + printf '%s\n' "$items" | fzf \ + --prompt='Project > ' \ + --height=100% --layout=reverse \ + --print-query --expect=enter +)" || exit 0 + +key="$(printf '%s\n' "$sel" | sed -n '1p')" +query="$(printf '%s\n' "$sel" | sed -n '2p' | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" +choice="$(printf '%s\n' "$sel" | sed -n '3p')" + +project="${choice:-$query}" +[ -n "$project" ] || exit 0 + +tmuxinator start "$project" +exit 0 + diff --git a/tmux/tmux.conf b/tmux/tmux.conf index c779094..a838ba3 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -66,5 +66,7 @@ set -g @plugin 'omerxx/tmux-sessionx' set -g @plugin 'christoomey/vim-tmux-navigator' +bind-key s display-popup -w 30% -h 30% -E "~/.config/tmux/bin/fuzzy-switch.sh" + # Initialise tmux plugin manager (needs to be at the bottom of the file) run '~/.config/tmux/plugins/tpm/tpm'