Add session switcher popup binding

This commit is contained in:
Kenneth Benzie 2025-06-27 11:59:47 +01:00
parent 8c92370420
commit 002c2ba9b8
2 changed files with 28 additions and 0 deletions

26
session.sh Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -e
sessions=()
# Get list of predefined session layouts
for item in $HOME/.local/share/tmux/layouts/session-*; do
sessions+=(${item#$HOME/.local/share/tmux/layouts/session-})
done
# Get list of existing sessions
sessions+=($(tmux list-sessions | awk -F: '{print $1}'))
# Pick the session with fzf (remove duplicates)
session=$(
echo "${sessions[@]}" | 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 -B -w 60 -h 10 -E '~/.config/tmux/session.sh'
# Restore old next/previous window bindings
bind C-n next-window