From a7883240265ffebfd2b22b811b68a0cbf3e697ce Mon Sep 17 00:00:00 2001 From: david Date: Wed, 1 Oct 2025 15:43:32 -0500 Subject: [PATCH] Adjust behavior for closing tmux sessions via keybinds --- src_files/.config/tmux/.tmux-session-hydrate-default | 4 ++-- src_files/.config/tmux/tmux.conf | 7 +++---- src_files/.local/scripts/tmux-session-close | 5 +++++ src_files/.local/scripts/tmux-session-init | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100755 src_files/.local/scripts/tmux-session-close diff --git a/src_files/.config/tmux/.tmux-session-hydrate-default b/src_files/.config/tmux/.tmux-session-hydrate-default index a9c4797..8fd4d9a 100644 --- a/src_files/.config/tmux/.tmux-session-hydrate-default +++ b/src_files/.config/tmux/.tmux-session-hydrate-default @@ -8,8 +8,8 @@ tmux_omitted_dirs=( [[ ! ${tmux_omitted_dirs[(re)$(pwd)]} ]] && { tmux new-window -d -n $EDITOR tmux send-keys -t :$EDITOR "$EDITOR ." c-M - tmux new-window -d -n debug - tmux new-window -d -n run + tmux new-window -d -n d-oc + tmux new-window -d -n procs tmux rename-window cmd tmux send-keys -t :cmd "clear; [[ -d .git ]] && git status" c-M } diff --git a/src_files/.config/tmux/tmux.conf b/src_files/.config/tmux/tmux.conf index a09af94..c07ec66 100644 --- a/src_files/.config/tmux/tmux.conf +++ b/src_files/.config/tmux/tmux.conf @@ -25,10 +25,9 @@ bind -r l select-pane -R # reload tmux.conf bind-key r source-file "$XDG_CONFIG_HOME/tmux/tmux.conf" \; display-message "tmux.conf reloaded" -# kill the current session -# TODO: combine these into one command; must cover case when only 1 session remains -bind-key q rename-session zzzz-temp-kill\; switch-client -p\; kill-session -t zzzz-temp-kill -bind-key w kill-session +# closing the current session +bind-key q kill-session +bind-key w run-shell "$DIR_SCRIPTS/tmux-session-close #{session_name}" # creating new windows bind-key n new-window diff --git a/src_files/.local/scripts/tmux-session-close b/src_files/.local/scripts/tmux-session-close new file mode 100755 index 0000000..4657350 --- /dev/null +++ b/src_files/.local/scripts/tmux-session-close @@ -0,0 +1,5 @@ +#!/bin/zsh + +tmux_existing_sessions=$(tmux list-sessions 2> /dev/null) +[[ ${#tmux_existing_sessions[@]} -gt 1 ]] && $DIR_SCRIPTS/tmux-session-init hub +tmux kill-session -t $1 diff --git a/src_files/.local/scripts/tmux-session-init b/src_files/.local/scripts/tmux-session-init index f058f19..d1a03ff 100755 --- a/src_files/.local/scripts/tmux-session-init +++ b/src_files/.local/scripts/tmux-session-init @@ -10,7 +10,7 @@ tmux_hydrate() { [[ -f $tmux_hydrate_path ]] && tmux send-keys -t $1 "source $tmux_hydrate_path" c-M } -tmux_existing_sessions=$([[ -n $(pgrep tmux) ]] && tmux list-sessions || echo '') +tmux_existing_sessions=$(tmux list-sessions 2> /dev/null || echo '') tmux_search_dirs=( $DIR_HOME_BOX $DIR_DEV