mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-26 22:58:01 +00:00
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.
This commit is contained in:
@@ -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
|
|
||||||
@@ -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
|
|
||||||
79
config/tmux/sesh.sh
Executable file
79
config/tmux/sesh.sh
Executable file
@@ -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
|
||||||
@@ -89,7 +89,7 @@ bind C-p previous-window
|
|||||||
bind C-n next-window
|
bind C-n next-window
|
||||||
|
|
||||||
# global sessions
|
# 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 "last-session (via sesh) " L run-shell "sesh last"
|
||||||
bind -N "sesh ui" N display-popup -E "sesh ui"
|
bind -N "sesh ui" N display-popup -E "sesh ui"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user