Reattach tmux session if one exists

Tmux tweaks
This commit is contained in:
Robin C. 2025-01-22 00:14:21 +01:00
parent 6aefa9ad43
commit d82bed4d98
2 changed files with 19 additions and 5 deletions

View File

@ -249,8 +249,15 @@ if [ "$TMUX_START" == "y" ]; then
# Start tmux # Start tmux
if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
# Check if there are any existing tmux sessions
if tmux list-sessions &> /dev/null; then
# Attach to the first available session
exec tmux attach-session -t "$(tmux list-sessions -F '#{session_name}' | head -n 1)"
else
# Create a new session if no sessions exist
exec tmux exec tmux
fi fi
fi
EOF EOF
else else
echo "tmux will not start automatically." echo "tmux will not start automatically."

View File

@ -3,11 +3,18 @@ bind r source-file $XDG_CONFIG_HOME/tmux/tmux.conf \; display-message "Config re
# Bind Ctrl + Space to enter copy mode # Bind Ctrl + Space to enter copy mode
bind -n C-Space copy-mode bind -n C-Space copy-mode
set-option -g status-keys vi
set-window-option -g mode-keys vi set-window-option -g mode-keys vi
set -g status-right "#[fg=yellow]Copy Mode#[default]" set -g status-right "#[fg=yellow]Copy Mode#[default]"
set -g status on set -g status on
set -g status-justify left
set -g remain-on-exit off
set -g exit-empty on
# The problem with enabling mouse support is that it doesn't work in any other app # The problem with enabling mouse support is that it doesn't work in any other app
# set -g mouse on # set -g mouse on
@ -23,11 +30,11 @@ set -sa terminal-overrides "*:Tc"
set -g @dracula-plugins "battery weather time" set -g @dracula-plugins "battery weather time"
set -g @dracula-show-empty-plugins false set -g @dracula-show-empty-plugins false
set -g @dracula-left-icon-padding 0 set -g @dracula-left-icon-padding 1
set -g @dracula-show-powerline true set -g @dracula-show-powerline false
set -g @dracula-show-left-sep  #set -g @dracula-show-left-sep 
set -g @dracula-show-right-sep  #set -g @dracula-show-right-sep 
set -g @dracula-battery-label false set -g @dracula-battery-label false
set -g @dracula-show-battery-status true set -g @dracula-show-battery-status true