Add session switcher popup binding

This commit is contained in:
Kenneth Benzie 2025-06-27 11:59:47 +01:00
parent 3ce1f3d43c
commit 1735b5aa3a
2 changed files with 29 additions and 0 deletions

27
session.sh Executable file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bash
session=()
# Get list of predefined session layouts
for item in $HOME/.local/share/tmux/layouts/session-*; do
item=${item#$HOME/.local/share/tmux/layouts/}
session+=(${item#session-})
done
# Get list of existing sessions
for s in $(tmux list-sessions | awk -F: '{print $1}'); do
session+=($s)
done
# Pick the session with fzf (remove duplicates)
session=$(
echo "${session[@]}" | tr ' ' '\n' | sort -u |
fzf --layout=reverse --info=hidden --border=rounded --cycle
)
# Create the session if it doesn't alreayd exist
tmux list-sessions | grep "^$session:" &> /dev/null || \
tmux new-session -Ads $session -c $HOME
# Switch to the session
tmux switch-client -t $session

View File

@ -64,6 +64,8 @@ if -b '[ "`uname`" = "Darwin" ]' \
# Open a popup with running the default shell
bind C-t display-popup -d '#{pane_current_path}' -E '$SHELL'
# Open a popup with session creator/switcher
bind C-s display-popup -T 'Session' -B -E '~/.config/tmux/session.sh'
# Restore old next/previous window bindings
bind C-n next-window