From 9b7942a9fbdefd827204ce93e19343fecdd87876 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Wed, 4 Feb 2026 02:49:30 +0200 Subject: [PATCH] refactor(tmux): combine sesh scripts into single bash script Replace sesh-gum.sh and sesh-tmux.fish with a unified sesh.sh that cascades through available tools: gum, fzf-tmux, fzf, bash select. Falls back to native tmux choose-tree if sesh is not installed. --- config/tmux/sesh-gum.sh | 18 --------- config/tmux/sesh-tmux.fish | 18 --------- config/tmux/sesh.sh | 79 ++++++++++++++++++++++++++++++++++++++ config/tmux/tmux.conf | 2 +- 4 files changed, 80 insertions(+), 37 deletions(-) delete mode 100755 config/tmux/sesh-gum.sh delete mode 100755 config/tmux/sesh-tmux.fish create mode 100755 config/tmux/sesh.sh diff --git a/config/tmux/sesh-gum.sh b/config/tmux/sesh-gum.sh deleted file mode 100755 index 7a9db65..0000000 --- a/config/tmux/sesh-gum.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -# Get session list and pipe it to gum for selection -SESH_LIST=$( - sesh list -i \ - | gum filter \ - --limit 1 \ - --no-sort \ - --fuzzy \ - --placeholder 'Pick a sesh' \ - --height 50 \ - --prompt='⚡' -) - -# If a session was selected, connect to it -if [ "$SESH_LIST" != "" ]; then - sesh connect "$SESH_LIST" -fi diff --git a/config/tmux/sesh-tmux.fish b/config/tmux/sesh-tmux.fish deleted file mode 100755 index 0e75aac..0000000 --- a/config/tmux/sesh-tmux.fish +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env fish - -set selection (sesh list --icons | fzf-tmux -p 80%,70% \ - --no-sort --ansi --border-label ' sesh ' --prompt '⚡ ' \ - --header ' ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \ - --bind 'tab:down,btab:up' \ - --bind 'ctrl-a:change-prompt(⚡ )+reload(sesh list --icons)' \ - --bind 'ctrl-t:change-prompt(🪟 )+reload(sesh list -t --icons)' \ - --bind 'ctrl-g:change-prompt(⚙️ )+reload(sesh list -c --icons)' \ - --bind 'ctrl-x:change-prompt(📁 )+reload(sesh list -z --icons)' \ - --bind 'ctrl-f:change-prompt(🔎 )+reload(fd -H -d 2 -t d -E .Trash . ~)' \ - --bind 'ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(⚡ )+reload(sesh list --icons)' \ - --preview-window 'right:55%' \ - --preview 'sesh preview {}') - -if test -n "$selection" - sesh connect "$selection" -end diff --git a/config/tmux/sesh.sh b/config/tmux/sesh.sh new file mode 100755 index 0000000..0f2d32e --- /dev/null +++ b/config/tmux/sesh.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# Unified sesh session picker with cascading tool detection: +# 1. gum — simple fuzzy filter +# 2. fzf-tmux — rich UI with keybinds, preview, session kill +# 3. fzf — same as fzf-tmux but inline +# 4. select — bare minimum numbered menu + +set -euo pipefail + +# Fall back to native tmux session picker if sesh is not installed +if ! command -v sesh &>/dev/null; then + tmux choose-tree -Zs + exit 0 +fi + +pick_with_gum() { + sesh list -i \ + | gum filter \ + --limit 1 \ + --no-sort \ + --fuzzy \ + --placeholder 'Pick a sesh' \ + --height 50 \ + --prompt='⚡' +} + +FZF_COMMON_OPTS=( + --no-sort --ansi + --border-label ' sesh ' + --prompt '⚡ ' + --header ' ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' + --bind 'tab:down,btab:up' + --bind 'ctrl-a:change-prompt(⚡ )+reload(sesh list --icons)' + --bind 'ctrl-t:change-prompt(🪟 )+reload(sesh list -t --icons)' + --bind 'ctrl-g:change-prompt(⚙️ )+reload(sesh list -c --icons)' + --bind 'ctrl-x:change-prompt(📁 )+reload(sesh list -z --icons)' + --bind 'ctrl-f:change-prompt(🔎 )+reload(fd -H -d 2 -t d -E .Trash . ~)' + --bind 'ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(⚡ )+reload(sesh list --icons)' + --preview-window 'right:55%' + --preview 'sesh preview {}' +) + +pick_with_fzf_tmux() { + sesh list --icons | fzf-tmux -p 80%,70% "${FZF_COMMON_OPTS[@]}" +} + +pick_with_fzf() { + sesh list --icons | fzf "${FZF_COMMON_OPTS[@]}" +} + +pick_with_select() { + local sessions + mapfile -t sessions < <(sesh list) + if [[ ${#sessions[@]} -eq 0 ]]; then + return + fi + PS3="Select session: " + select choice in "${sessions[@]}"; do + if [[ -n "${choice-}" ]]; then + printf '%s' "$choice" + break + fi + done +} + +# Cascading tool detection +if command -v gum &>/dev/null; then + selection=$(pick_with_gum) +elif command -v fzf-tmux &>/dev/null; then + selection=$(pick_with_fzf_tmux) +elif command -v fzf &>/dev/null; then + selection=$(pick_with_fzf) +else + selection=$(pick_with_select) +fi + +if [[ -n "${selection-}" ]]; then + sesh connect "$selection" +fi diff --git a/config/tmux/tmux.conf b/config/tmux/tmux.conf index 0f0aff4..aa70f93 100644 --- a/config/tmux/tmux.conf +++ b/config/tmux/tmux.conf @@ -89,7 +89,7 @@ bind C-p previous-window bind C-n next-window # global sessions -bind -N "sesh selection" t display-popup -E "$HOME/.dotfiles/config/tmux/sesh-gum.sh" +bind -N "sesh selection" t display-popup -E "$HOME/.dotfiles/config/tmux/sesh.sh" bind -N "last-session (via sesh) " L run-shell "sesh last" bind -N "sesh ui" N display-popup -E "sesh ui"