Compare commits
10 Commits
87dbb4e498
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 385cce1f5b | |||
|
|
3061d27a12 | ||
|
|
0c6628edc0 | ||
|
|
f206ee5333 | ||
|
|
10e4ba07d5 | ||
| fb5edb0326 | |||
| 1d1d80f2f6 | |||
| 4db0b400ac | |||
| 9423387093 | |||
| 406922cdf1 |
177
.tmux.conf
177
.tmux.conf
@@ -1,105 +1,118 @@
|
|||||||
## make tmux display things in 256 colors
|
#########################################
|
||||||
## Getting italics working correctly in tmux
|
# Basic Settings and Prefix
|
||||||
## https://unix.stackexchange.com/a/745718
|
#########################################
|
||||||
set -g default-terminal "tmux-256color"
|
|
||||||
|
|
||||||
## set scrollback history to 10000 (10k)
|
set-option -g prefix C-a # Set Ctrl-a as the prefix key
|
||||||
set -g history-limit 10000
|
unbind C-b # Unbind the default Ctrl-b prefix
|
||||||
|
set -sg escape-time 1 # Shorten command delay for faster responsiveness
|
||||||
|
|
||||||
## set Ctrl-a as the default prefix key combination
|
#########################################
|
||||||
## and unbind C-b to free it up
|
# Terminal and Display
|
||||||
set -g prefix C-a
|
#########################################
|
||||||
unbind C-b
|
|
||||||
|
|
||||||
## reload ~/.tmux.conf using PREFIX r
|
set-option -g default-terminal "tmux-256color" # Force tmux to use 256 colors if supported by the terminal
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# History and Indexing
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g history-limit 10000 # Set the scrollback history limit to 10,000 lines
|
||||||
|
set-option -g base-index 1 # Start window indexing at 1 (instead of 0)
|
||||||
|
set-option -g pane-base-index 1 # Start pane indexing at 1 (instead of 0)
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Key Bindings
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
# Reload tmux configuration
|
||||||
bind r source-file ~/.tmux.conf \; display "Reloaded!"
|
bind r source-file ~/.tmux.conf \; display "Reloaded!"
|
||||||
|
|
||||||
## map Vi movement keys as pane movement keys
|
# Window Management
|
||||||
bind h select-pane -L
|
bind Tab next-window # Cycle to the next window
|
||||||
bind j select-pane -D
|
bind , command-prompt "rename-window '%%'" # Open a prompt to rename the current window
|
||||||
bind k select-pane -U
|
|
||||||
bind l select-pane -R
|
|
||||||
|
|
||||||
# resize panes using PREFIX H, J, K, L
|
# Pane Management
|
||||||
bind -r H resize-pane -L 2
|
bind | split-window -h # Split the current window horizontally
|
||||||
bind -r J resize-pane -D 2
|
bind - split-window -v # Split the current window vertically
|
||||||
bind -r K resize-pane -U 2
|
|
||||||
bind -r L resize-pane -R 2
|
|
||||||
|
|
||||||
## PREFIX | to split horizontally
|
# Pane Selection (Vi-style movement)
|
||||||
## PREFIX - to split vertically
|
bind h select-pane -L # Select the pane to the left
|
||||||
bind | split-window -h
|
bind j select-pane -D # Select the pane below
|
||||||
bind - split-window -v
|
bind k select-pane -U # Select the pane above
|
||||||
|
bind l select-pane -R # Select the pane to the right
|
||||||
|
|
||||||
## shorten command delay
|
# Pane Resizing
|
||||||
set -sg escape-time 1
|
bind -r H resize-pane -L 2 # Resize the current pane 2 cells to the left (repeatable with -r)
|
||||||
|
bind -r J resize-pane -D 2 # Resize the current pane 2 cells down (repeatable with -r)
|
||||||
|
bind -r K resize-pane -U 2 # Resize the current pane 2 cells up (repeatable with -r)
|
||||||
|
bind -r L resize-pane -R 2 # Resize the current pane 2 cells to the right (repeatable with -r)
|
||||||
|
|
||||||
## Tab through active windows
|
#########################################
|
||||||
bind Tab next-window
|
# Visual Notifications
|
||||||
|
#########################################
|
||||||
|
|
||||||
## Rename window
|
set-option -g monitor-activity on # Enable monitoring of activity in other windows
|
||||||
bind , command-prompt "rename-window '%%'"
|
set-option -g visual-activity on # Enable visual notification of activity in other windows
|
||||||
|
|
||||||
## ----------------------
|
#########################################
|
||||||
## Status Bar
|
# Status Bar
|
||||||
## -----------------------
|
#########################################
|
||||||
set -g status on # turn the status bar on
|
|
||||||
set -g status-interval 5 # set update frequencey (default 15 seconds)
|
|
||||||
set -g status-justify centre # center window list for clarity
|
|
||||||
|
|
||||||
## ----------------------
|
set-option -g status on # Turn the status bar on
|
||||||
## set some pretty colors
|
set-option -g status-interval 5 # Set the status bar update frequency to 5 seconds
|
||||||
## ----------------------
|
set-option -g status-justify centre # Justify the window list to the left
|
||||||
## set pane colors - hilight the active pane
|
|
||||||
set -g pane-border-style bg=colour0,fg=colour8
|
|
||||||
set -g pane-active-border-style bg=colour0,fg=colour2
|
|
||||||
|
|
||||||
## colorize messages in the command line
|
# Left side of the status bar
|
||||||
set-option -g message-style bg=colour0,fg=colour13
|
set-option -g status-left-length 70 # Set the maximum length of the left side of the status bar
|
||||||
|
set-option -g status-left "#h ◆" # Display the hostname on the left, followed by some visual separators
|
||||||
|
|
||||||
## set window list colors
|
# Right side of the status bar
|
||||||
setw -g window-status-style fg=colour8,bg=colour0
|
set-option -g status-right-length 60 # Set the maximum length of the right side of the status bar
|
||||||
setw -g window-status-current-style fg=colour2,bg=colour0,bright
|
set-option -g status-right "S:#S W:#I P:#P | %b %d %H:%M" # Display session name, window index, pane index, and the date/time on the right
|
||||||
|
|
||||||
## Titles
|
# Status bar style
|
||||||
set -g set-titles on
|
set-option -g status-style bg=#000000,fg=grey # Set the background to default (transparent), foreground color, and brightness
|
||||||
set -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name, active(or not)
|
|
||||||
|
|
||||||
#set inactive/active window styles
|
#########################################
|
||||||
# set -g window-style fg=colour0,bg=colour0
|
# Pane Appearance
|
||||||
# set -g window-active-style fg=colour7,bg=colour0
|
#########################################
|
||||||
# -- or --
|
|
||||||
# These make tmux transparent again
|
|
||||||
set -g window-style bg=default
|
|
||||||
set -g window-active-style bg=default
|
|
||||||
|
|
||||||
## Status Bar: color
|
set-option -g pane-border-style bg=colour0,fg=colour8 # Style for inactive pane borders
|
||||||
set-option -g status-style bg=colour0,fg=colour8,bright
|
set-option -g pane-active-border-style bg=colour0,fg=colour2 # Style for the active pane border
|
||||||
|
|
||||||
## Status Bar: Left - hostname
|
#########################################
|
||||||
set -g status-left-length 70
|
# Message Appearance
|
||||||
set -g status-left "#h"
|
#########################################
|
||||||
|
|
||||||
## Status Bar: Right - Session name, Window & Pane, Date & Time
|
set-option -g message-style bg=default,fg=colour13 # Style for messages displayed in the tmux command line
|
||||||
set -g status-right-length 60
|
|
||||||
set -g status-right "S:#S W:#I P:#P | %Y-%m-%d %H:%M"
|
|
||||||
|
|
||||||
# set window and pane index to 1 (0 by default)
|
#########################################
|
||||||
set -g base-index 1
|
# Window Appearance
|
||||||
setw -g pane-base-index 1
|
#########################################
|
||||||
|
|
||||||
## visual notification of activity in other windows
|
set-window-option -g window-style bg=default # Default background color for windows
|
||||||
setw -g monitor-activity on
|
set-window-option -g window-active-style bg=default # Background color for the active window
|
||||||
set -g visual-activity on
|
|
||||||
|
|
||||||
# ----------------------------------
|
#########################################
|
||||||
|
# Window List Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
# ## use send-prefix to pass C-a through to application
|
#set-window-option -g window-status-style fg=blue # Or your preferred inactive style
|
||||||
# #bind C-a send-prefix
|
#set-window-option -g window-status-format "#[fg=blue] #I:#W#[fg=blue]#{?window_activity_flag,#[fg=yellow bg=default]!,}"
|
||||||
#
|
#set-window-option -g window-status-current-style fg=green,bright
|
||||||
# ## Make the current window the first window
|
#set-window-option -g window-status-current-format "#[fg=green,bright]● #I:#W ●#[fg=green]"
|
||||||
# bind T swap-window -t 1
|
|
||||||
#
|
# Stolen from https://github.com/mhartington/dotfiles/blob/main/config/tmux/tmux-status.conf
|
||||||
# set-option -g display-panes-active-colour colour2
|
|
||||||
# set-option -g display-panes-colour colour1
|
# Not active window
|
||||||
#
|
set-window-option -g window-status-format "#{?window_activity_flag,#[bg=#ffff00 fg=#000000 bold],#[fg=#228b22 bg=default]}#I:#W"
|
||||||
|
|
||||||
|
# Active window
|
||||||
|
set-window-option -g window-status-current-format "#[bg=default fg=#7cfc00]● #I:#W"
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window Titles
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g set-titles on # Enable automatic window titles
|
||||||
|
set-option -g set-titles-string '#H:#S.#I.#P #W #T' # Format string for window titles (hostname:session.window_index.pane_index window_number window_name)
|
||||||
|
|||||||
119
.tmux.conf.home
Normal file
119
.tmux.conf.home
Normal file
@@ -0,0 +1,119 @@
|
|||||||
|
#########################################
|
||||||
|
# Basic Settings and Prefix
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g prefix C-a # Set Ctrl-a as the prefix key
|
||||||
|
unbind C-b # Unbind the default Ctrl-b prefix
|
||||||
|
set -sg escape-time 1 # Shorten command delay for faster responsiveness
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Terminal and Display
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g default-terminal "tmux-256color" # Force tmux to use 256 colors if supported by the terminal
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# History and Indexing
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g history-limit 10000 # Set the scrollback history limit to 10,000 lines
|
||||||
|
set-option -g base-index 1 # Start window indexing at 1 (instead of 0)
|
||||||
|
set-option -g pane-base-index 1 # Start pane indexing at 1 (instead of 0)
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Key Bindings
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
# Reload tmux configuration
|
||||||
|
bind r source-file ~/.tmux.conf \; display "Reloaded!"
|
||||||
|
|
||||||
|
# Window Management
|
||||||
|
bind Tab next-window # Cycle to the next window
|
||||||
|
bind , command-prompt "rename-window '%%'" # Open a prompt to rename the current window
|
||||||
|
|
||||||
|
# Pane Management
|
||||||
|
bind | split-window -h # Split the current window horizontally
|
||||||
|
bind - split-window -v # Split the current window vertically
|
||||||
|
|
||||||
|
# Pane Selection (Vi-style movement)
|
||||||
|
bind h select-pane -L # Select the pane to the left
|
||||||
|
bind j select-pane -D # Select the pane below
|
||||||
|
bind k select-pane -U # Select the pane above
|
||||||
|
bind l select-pane -R # Select the pane to the right
|
||||||
|
|
||||||
|
# Pane Resizing
|
||||||
|
bind -r H resize-pane -L 2 # Resize the current pane 2 cells to the left (repeatable with -r)
|
||||||
|
bind -r J resize-pane -D 2 # Resize the current pane 2 cells down (repeatable with -r)
|
||||||
|
bind -r K resize-pane -U 2 # Resize the current pane 2 cells up (repeatable with -r)
|
||||||
|
bind -r L resize-pane -R 2 # Resize the current pane 2 cells to the right (repeatable with -r)
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Visual Notifications
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g monitor-activity on # Enable monitoring of activity in other windows
|
||||||
|
set-option -g visual-activity on # Enable visual notification of activity in other windows
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Status Bar
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g status on # Turn the status bar on
|
||||||
|
set-option -g status-interval 5 # Set the status bar update frequency to 5 seconds
|
||||||
|
set-option -g status-justify centre # Justify the window list to the left
|
||||||
|
|
||||||
|
# Left side of the status bar
|
||||||
|
set-option -g status-left-length 70 # Set the maximum length of the left side of the status bar
|
||||||
|
set-option -g status-left "#h ◆" # Display the hostname on the left, followed by some visual separators
|
||||||
|
|
||||||
|
# Right side of the status bar
|
||||||
|
set-option -g status-right-length 60 # Set the maximum length of the right side of the status bar
|
||||||
|
set-option -g status-right "S:#S W:#I P:#P | %b %d %H:%M" # Display session name, window index, pane index, and the date/time on the right
|
||||||
|
|
||||||
|
# Status bar style
|
||||||
|
set-option -g status-style bg=#000000,fg=grey # Set the background to default (transparent), foreground color, and brightness
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Pane Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g pane-border-style bg=colour0,fg=colour8 # Style for inactive pane borders
|
||||||
|
set-option -g pane-active-border-style bg=colour0,fg=colour2 # Style for the active pane border
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Message Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g message-style bg=default,fg=colour13 # Style for messages displayed in the tmux command line
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-window-option -g window-style bg=default # Default background color for windows
|
||||||
|
set-window-option -g window-active-style bg=default # Background color for the active window
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window List Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
#set-window-option -g window-status-style fg=blue # Or your preferred inactive style
|
||||||
|
#set-window-option -g window-status-format "#[fg=blue] #I:#W#[fg=blue]#{?window_activity_flag,#[fg=yellow bg=default]!,}"
|
||||||
|
#set-window-option -g window-status-current-style fg=green,bright
|
||||||
|
#set-window-option -g window-status-current-format "#[fg=green,bright]● #I:#W ●#[fg=green]"
|
||||||
|
|
||||||
|
# Stolen from https://github.com/mhartington/dotfiles/blob/main/config/tmux/tmux-status.conf
|
||||||
|
|
||||||
|
# Not active window
|
||||||
|
set-window-option -g window-status-format "#{?window_activity_flag,#[bg=#ffff00 fg=#000000 bold],#[fg=#228b22 bg=default]}#I:#W"
|
||||||
|
|
||||||
|
# Active window
|
||||||
|
set-window-option -g window-status-current-format "#[bg=default fg=#7cfc00]● #I:#W"
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window Titles
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g set-titles on # Enable automatic window titles
|
||||||
|
set-option -g set-titles-string '#H:#S.#I.#P #W #T' # Format string for window titles (hostname:session.window_index.pane_index window_number window_name)
|
||||||
|
|
||||||
118
.tmux.conf.work
Normal file
118
.tmux.conf.work
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
#########################################
|
||||||
|
# Basic Settings and Prefix
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g prefix C-a # Set Ctrl-a as the prefix key
|
||||||
|
unbind C-b # Unbind the default Ctrl-b prefix
|
||||||
|
set -sg escape-time 1 # Shorten command delay for faster responsiveness
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Terminal and Display
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g default-terminal "tmux-256color" # Force tmux to use 256 colors if supported by the terminal
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# History and Indexing
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g history-limit 10000 # Set the scrollback history limit to 10,000 lines
|
||||||
|
set-option -g base-index 1 # Start window indexing at 1 (instead of 0)
|
||||||
|
set-option -g pane-base-index 1 # Start pane indexing at 1 (instead of 0)
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Key Bindings
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
# Reload tmux configuration
|
||||||
|
bind r source-file ~/.tmux.conf \; display "Reloaded!"
|
||||||
|
|
||||||
|
# Window Management
|
||||||
|
bind Tab next-window # Cycle to the next window
|
||||||
|
bind , command-prompt "rename-window '%%'" # Open a prompt to rename the current window
|
||||||
|
|
||||||
|
# Pane Management
|
||||||
|
bind | split-window -h # Split the current window horizontally
|
||||||
|
bind - split-window -v # Split the current window vertically
|
||||||
|
|
||||||
|
# Pane Selection (Vi-style movement)
|
||||||
|
bind h select-pane -L # Select the pane to the left
|
||||||
|
bind j select-pane -D # Select the pane below
|
||||||
|
bind k select-pane -U # Select the pane above
|
||||||
|
bind l select-pane -R # Select the pane to the right
|
||||||
|
|
||||||
|
# Pane Resizing
|
||||||
|
bind -r H resize-pane -L 2 # Resize the current pane 2 cells to the left (repeatable with -r)
|
||||||
|
bind -r J resize-pane -D 2 # Resize the current pane 2 cells down (repeatable with -r)
|
||||||
|
bind -r K resize-pane -U 2 # Resize the current pane 2 cells up (repeatable with -r)
|
||||||
|
bind -r L resize-pane -R 2 # Resize the current pane 2 cells to the right (repeatable with -r)
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Visual Notifications
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g monitor-activity on # Enable monitoring of activity in other windows
|
||||||
|
set-option -g visual-activity on # Enable visual notification of activity in other windows
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Status Bar
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g status on # Turn the status bar on
|
||||||
|
set-option -g status-interval 5 # Set the status bar update frequency to 5 seconds
|
||||||
|
set-option -g status-justify centre # Justify the window list to the left
|
||||||
|
|
||||||
|
# Left side of the status bar
|
||||||
|
set-option -g status-left-length 70 # Set the maximum length of the left side of the status bar
|
||||||
|
set-option -g status-left "#h ◆" # Display the hostname on the left, followed by some visual separators
|
||||||
|
|
||||||
|
# Right side of the status bar
|
||||||
|
set-option -g status-right-length 60 # Set the maximum length of the right side of the status bar
|
||||||
|
set-option -g status-right "S:#S W:#I P:#P | %b %d %H:%M" # Display session name, window index, pane index, and the date/time on the right
|
||||||
|
|
||||||
|
# Status bar style
|
||||||
|
set-option -g status-style bg=#000000,fg=colour8,bright # Set the background to default (transparent), foreground color, and brightness
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Pane Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g pane-border-style bg=colour0,fg=colour8 # Style for inactive pane borders
|
||||||
|
set-option -g pane-active-border-style bg=colour0,fg=colour2 # Style for the active pane border
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Message Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g message-style bg=default,fg=colour13 # Style for messages displayed in the tmux command line
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g window-style bg=default # Default background color for windows
|
||||||
|
set-option -g window-active-style bg=default # Background color for the active window
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window List Appearance
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
#set-option -g window-status-current-format "#[fg=colour2,bg=colour0]● #I:#W ●#[fg=colour2,bg=colour0]"
|
||||||
|
#set-option -g window-status-style fg=colour8,bg=default # Or your preferred inactive style
|
||||||
|
#set-option -g window-status-current-style fg=colour2,bg=default,bright
|
||||||
|
#set-option -g window-status-format "#[fg=colour8,bg=default] #I:#W#[fg=colour8,bg=default]#{?window_activity_flag,#[fg=colour11]! ,}"
|
||||||
|
|
||||||
|
# Stolen from https://github.com/mhartington/dotfiles/blob/main/config/tmux/tmux-status.conf
|
||||||
|
|
||||||
|
# Not active window
|
||||||
|
set-window-option -g window-status-format "#{?window_activity_flag,#[bg=#8802ad fg=#000000 bold],#[fg=#5e708c bg=default]}#I:#W"
|
||||||
|
|
||||||
|
# Active window
|
||||||
|
set-window-option -g window-status-current-format "#[bg=default fg=#059df5]● #I:#W"
|
||||||
|
|
||||||
|
#########################################
|
||||||
|
# Window Titles
|
||||||
|
#########################################
|
||||||
|
|
||||||
|
set-option -g set-titles on # Enable automatic window titles
|
||||||
|
set-option -g set-titles-string '#H:#S.#I.#P #W #T' # Format string for window titles (hostname:session.window_index.pane_index window_number window_name)
|
||||||
94
README.md
94
README.md
@@ -1,74 +1,70 @@
|
|||||||
---
|
---
|
||||||
filecreated:
|
CREATED : 2026-03-03
|
||||||
fileupdated: 2025-04-16
|
UPDATED : 2026-03-03
|
||||||
filetags: [readme]
|
AUTHOR : chawley
|
||||||
---
|
---
|
||||||
|
|
||||||
# tmux-menu.sh
|
# TMUX Hack Session Launcher
|
||||||
|
|
||||||
A hack tmux menu script to manage multiple tmux sessions
|
A Bash script designed to manage and automate pre-defined tmux-sessions. This script allows you to launch complex development or administration environments - complete with multiple windows and SSH connections - using a single command.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
REQ: tmux v3+
|
## Features
|
||||||
|
|
||||||
|
- **Automated Session Creation**: Checks if a session exists; if not, it creates it with your pre-defined windows and layouts.
|
||||||
|
- **Environment Nesting Protection**: Prevents launching a new session if you are already inside an active tmux environment.
|
||||||
|
- **Custom Configuration Support**: Automatically sources your `$HOME/.tmux.conf`.
|
||||||
|
- **Session Attaching**: If a requested session is already running, the script simply attaches you to it.
|
||||||
|
- **Fallback Discovery**: Provides an error message and lists all currently active sessions if an invalid name is provided.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Need
|
## Prerequisites
|
||||||
|
|
||||||
After I discovered tmux I searched for a way to manage multiple groups of tmux sessions under one unified script. Not finding anything (or maybe just not looking well enough) I decided to write my own. It's not pretty, but I've been using for a couple of years now and it's become an integral part of my workflow.
|
- **tmux**: Ensure `tmux` is installed and available in your `$PATH`.
|
||||||
|
- **SSH Config (Optional)**: For windows that execute SSH commands, ensure your SSH keys or config are set up for seamless connections.
|
||||||
|
|
||||||
My setup works this way:
|
---
|
||||||
|
|
||||||
Imagine you have multiple SSH connections
|
## Installation
|
||||||
|
|
||||||
- web-dev
|
1. Copy the script to a directory in your `$PATH` (e.g., `~/bin` or `/usr/local/bin`).
|
||||||
- web-prod
|
2. Rename it to something short, like `tm`.
|
||||||
- database-dev
|
3. Make the script executable:
|
||||||
- database-prod
|
```bash
|
||||||
|
chmod +x ~/bin/tm
|
||||||
|
```
|
||||||
|
|
||||||
and you want to group them together in similar groups.
|
---
|
||||||
|
|
||||||
With this script you can name collections of sessions and switch between them easily with just a few keystrokes.
|
## Usage
|
||||||
|
|
||||||
Let's see an example using the above connections:
|
Run the script followed by the name of the pre-defined session:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
case $session in
|
tm mine
|
||||||
web)
|
```
|
||||||
if [[ $tcheck == 0 ]]; then
|
|
||||||
tmux new-session -d -s web
|
|
||||||
tmux rename-window 'local'
|
|
||||||
tmux new-window -t 1 -n 'root@web-dev' 'exec ssh root@web-dev.example.org'
|
|
||||||
tmux new-window -t:2 -n 'user@web-prod' 'exec ssh user@webprod.example.org'
|
|
||||||
fi
|
|
||||||
tmux attach-session -t web
|
|
||||||
;;
|
|
||||||
|
|
||||||
case $session in
|
If no session name is provided, or the name doesn't match a case in the script, it will display an error and list all currently active tmux sessions.
|
||||||
database)
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
To add a new session, add a new case stanza inside the `case $session in` block.
|
||||||
|
|
||||||
|
### Template
|
||||||
|
```bash
|
||||||
|
session_name)
|
||||||
if [[ $tcheck == 0 ]]; then
|
if [[ $tcheck == 0 ]]; then
|
||||||
tmux new-session -d -s database
|
tmux -f "${TMUX_CONF}" new-session -d -s session_name
|
||||||
tmux rename-window 'local'
|
tmux -f "${TMUX_CONF}" rename-window 'initial_window'
|
||||||
tmux new-window -t 1 -n 'root@database-dev' 'exec ssh root@databasedev.example.org'
|
tmux -f "${TMUX_CONF}" new-window -t:1 -n 'second_window' 'command_to_run'
|
||||||
tmux new-window -t:2 -n 'user@database-prod' 'exec ssh user@wdatabase.example.org'
|
|
||||||
fi
|
fi
|
||||||
tmux attach-session -t database
|
tmux attach-session -t session_name
|
||||||
;;
|
;;
|
||||||
```
|
```
|
||||||
|
|
||||||
Calling the script with a pre-determined session name (ex: `./tmux-menu.sh web` or `./tmux-menu.sh database`) firstchecks to see if there is already a session group with that name. If not, it creates a new group with the commands youspecify and names each connection in tmux.
|
### Script Variables
|
||||||
|
- `TMUX_CONF`: Defaults to `$HOME/.tmux.conf`. Modify this variable if your configuration file is located elsewhere.
|
||||||
If the session group *does* already exist, it simply switches you to that group.
|
|
||||||
|
|
||||||
If you alias `tmux-menu.sh` to something shorter (like `tm`), switching between active sessions is as easy as `Ctrl-A + d` (to detach) and `tm web` (to attach or create the web group).
|
|
||||||
|
|
||||||
Killing session groups is as easy as `tmux-session kill -t web`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Use
|
|
||||||
|
|
||||||
I've found that I use this script on different servers with different configurations. So I copy the `tmux-menu.template.sh` to `$HOME/tmux-menu.sh` and then alias that to `tm`.
|
|
||||||
|
|
||||||
I also include my `.tmux.conf` file with comments about what does what. If you choose to use it, make sure to copy it to your home directory.
|
|
||||||
|
|||||||
@@ -1,39 +1,30 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
#
|
#
|
||||||
# CREATED : 2026-02-21
|
# CREATED : 2015-09-09
|
||||||
# UPDATED :
|
# UPDATED : 2026-03-03
|
||||||
# USAGE :
|
# USAGE :
|
||||||
# DESC : Hack tmux session launcher. Reads a YAML file to create a tmux # session with multiple windows and commands.
|
# DESC : A hack script I wrote to help me manage pre-defined
|
||||||
|
# tmux-sessions
|
||||||
# NOTES :
|
# NOTES :
|
||||||
# AUTHOR : chawley
|
# AUTHOR : chawley
|
||||||
#
|
#
|
||||||
#===============================================================================
|
#===============================================================================
|
||||||
|
|
||||||
# Path to the YAML configuration file
|
|
||||||
TMUX_CONFIG_FILE="${HOME}/.config/tmux-menu/sessions.yaml"
|
|
||||||
|
|
||||||
# Check for yq (YAML processor)
|
|
||||||
if ! command -v yq &> /dev/null; then
|
|
||||||
echo "Error: 'yq' command not found."
|
|
||||||
echo "Please install yq (https://github.com/mikefarah/yq) to use this script."
|
|
||||||
echo "Example: 'sudo snap install yq' or 'brew install yq'"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# check for command line argument
|
|
||||||
# Tips from:
|
|
||||||
# http://stackoverflow.com/questions/7832080/test-if-a-variable-is-set-in-bash-when-using-set-o-nounset
|
|
||||||
if [ -z "${1:-}" ]; then
|
if [ -z "${1:-}" ]; then
|
||||||
session="undefined"
|
session="undefined"
|
||||||
else
|
else
|
||||||
session=$1
|
session=$1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Change this to your tmux config file if it's not in the home directory or named differently
|
||||||
|
TMUX_CONF="-f $HOME/.tmux.conf"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo ""
|
echo ""
|
||||||
echo "##################################"
|
echo "----------------------------------"
|
||||||
echo "TMUX Hack Session Launcher"
|
echo "TMUX Hack Session Launcher"
|
||||||
echo "##################################"
|
echo "----------------------------------"
|
||||||
echo "Launching Session: $session"
|
echo "Launching Session: $session"
|
||||||
|
|
||||||
# NO TMUX NESTING ALLOWED
|
# NO TMUX NESTING ALLOWED
|
||||||
@@ -43,66 +34,49 @@ if [ ! -z $TMUX ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
tcheck=$(tmux list-sessions | grep -c "${session}") # check if session is active
|
||||||
|
|
||||||
# if session is active, switch to it.
|
# if session is active, switch to it. If not active but part of the list below,
|
||||||
if tmux has-session -t "${session}" 2>/dev/null; then
|
# create it. Finally, if no session or undefined session is passed, give an
|
||||||
echo "Session '${session}' already active. Attaching..."
|
# error message and list the active sessions
|
||||||
tmux attach-session -t "${session}"
|
|
||||||
exit 0
|
# sample session definition
|
||||||
|
#
|
||||||
|
# case $session in
|
||||||
|
# analytics) # <- session name
|
||||||
|
# if [[ $tcheck == 0 ]]; then # <- check if it's already running
|
||||||
|
# tmux new-session -d -s analytics # <- if not, create it
|
||||||
|
# tmux -f "${TMUX_CONF}" rename-window 'localhost' # <- rename the first window (local)
|
||||||
|
# # ↓↓ --- define additional windows --- ↓↓
|
||||||
|
# tmux -f "${TMUX_CONF}" new-window -t:1 -n 'lasis01' 'exec ssh lasis01'
|
||||||
|
# tmux -f "${TMUX_CONF}" new-window -t:2 -n 'lasis01dev' 'exec ssh lasis01dev'
|
||||||
|
# tmux -f "${TMUX_CONF}" new-window -t:3 -n 'ldssbox01' 'exec ssh ldssbox01'
|
||||||
|
# tmux -f "${TMUX_CONF}" new-window -t:4 -n 'lpdprod01' 'exec ssh lpdprod01'
|
||||||
|
# tmux -f "${TMUX_CONF}" new-window -t:5 -n 'ldatalake01' 'exec ssh ldatalake01'
|
||||||
|
# tmux -f "${TMUX_CONF}" new-window -t:6 -n 'lsandbox' 'exec ssh lsandbox'
|
||||||
|
# fi
|
||||||
|
# tmux attach-session -t analytics # <- if window active, switch to it
|
||||||
|
# ;;
|
||||||
|
|
||||||
|
case $session in
|
||||||
|
mine)
|
||||||
|
if [[ $tcheck == 0 ]]; then
|
||||||
|
tmux -f "${TMUX_CONF}" new-session -d -s mine
|
||||||
|
tmux -f "${TMUX_CONF}" rename-window 'local(aristotle)'
|
||||||
|
tmux -f "${TMUX_CONF}" new-window -t 1 -n 'root@vps' 'exec ssh root@vps.example.org'
|
||||||
|
tmux -f "${TMUX_CONF}" new-window -t:2 -n 'chawley@phaedrus' 'exec ssh chawley@phaedrus'
|
||||||
|
tmux -f "${TMUX_CONF}" new-window -t:3 -n 'chawley@homer' 'exec ssh chawley@homer.simpsons.net'
|
||||||
fi
|
fi
|
||||||
|
tmux attach-session -t mine
|
||||||
|
;;
|
||||||
|
|
||||||
# Check if the config file exists
|
# add more sessions here inside a case stanza. Start with a session name and end with ';;'
|
||||||
if [ ! -f "${TMUX_CONFIG_FILE}" ]; then
|
|
||||||
echo "Error: tmux session configuration file not found at '${TMUX_CONFIG_FILE}'."
|
|
||||||
echo "Please create it with your session definitions."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the requested session exists in the YAML file
|
*)
|
||||||
if ! yq e ".sessions.${session}" "${TMUX_CONFIG_FILE}" &> /dev/null; then
|
|
||||||
echo "### ERROR No Such Session ###"
|
echo "### ERROR No Such Session ###"
|
||||||
echo "Usage: $(basename "$0") <session_name>"
|
echo "Usage: tm <session_name>"
|
||||||
echo "Available Sessions from '${TMUX_CONFIG_FILE}':"
|
echo "Active Sessions:"
|
||||||
echo "---------------------------------------"
|
echo "----------------"
|
||||||
yq e '.sessions | keys | .[]' "${TMUX_CONFIG_FILE}" 2>/dev/null || echo "No sessions defined."
|
tmux list-sessions
|
||||||
echo ""
|
;;
|
||||||
echo "Active tmux Sessions:"
|
esac
|
||||||
echo "---------------------"
|
|
||||||
tmux list-sessions 2>/dev/null || echo "No active sessions."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Creating new session '${session}' from '${TMUX_CONFIG_FILE}'..."
|
|
||||||
|
|
||||||
# Get the number of windows for the session
|
|
||||||
num_windows=$(yq e ".sessions.${session}.windows | length" "${TMUX_CONFIG_FILE}")
|
|
||||||
|
|
||||||
if [[ "${num_windows}" -eq 0 ]]; then
|
|
||||||
echo "Error: Session '${session}' has no windows defined in '${TMUX_CONFIG_FILE}'."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create the first window (which also creates the session)
|
|
||||||
first_window_name=$(yq e ".sessions.${session}.windows[0].name" "${TMUX_CONFIG_FILE}")
|
|
||||||
first_window_command=$(yq e ".sessions.${session}.windows[0].command // \"\"" "${TMUX_CONFIG_FILE}")
|
|
||||||
|
|
||||||
if [[ -z "${first_window_command}" ]]; then
|
|
||||||
tmux new-session -d -s "${session}" -n "${first_window_name}"
|
|
||||||
else
|
|
||||||
tmux new-session -d -s "${session}" -n "${first_window_name}" "${first_window_command}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create subsequent windows
|
|
||||||
for ((i=1; i<num_windows; i++)); do
|
|
||||||
window_name=$(yq e ".sessions.${session}.windows[${i}].name" "${TMUX_CONFIG_FILE}")
|
|
||||||
window_command=$(yq e ".sessions.${session}.windows[${i}].command // \"\"" "${TMUX_CONFIG_FILE}")
|
|
||||||
|
|
||||||
if [[ -z "${window_command}" ]]; then
|
|
||||||
tmux new-window -t "${session}:${i}" -n "${window_name}"
|
|
||||||
else
|
|
||||||
tmux new-window -t "${session}:${i}" -n "${window_name}" "${window_command}"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Attach to the newly created session
|
|
||||||
tmux attach-session -t "${session}"
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
---
|
|
||||||
# tmux session definitions for tmux-menu.sh
|
|
||||||
# Place this file at ~/.config/tmux-menu/sessions.yaml
|
|
||||||
|
|
||||||
sessions:
|
|
||||||
mine:
|
|
||||||
windows:
|
|
||||||
- name: "local(aristotle)"
|
|
||||||
command: "" # Default to shell
|
|
||||||
- name: "root@vps"
|
|
||||||
command: "exec ssh root@vps.example.org"
|
|
||||||
- name: "chawley@phaedrus"
|
|
||||||
command: "exec ssh chawley@phaedrus"
|
|
||||||
- name: "chawley@homer"
|
|
||||||
command: "exec ssh chawley@homer.simpsons.net"
|
|
||||||
# Add more sessions here
|
|
||||||
# example_session:
|
|
||||||
# windows:
|
|
||||||
# - name: "local_shell"
|
|
||||||
# command: ""
|
|
||||||
# - name: "remote_server"
|
|
||||||
# command: "ssh user@remote"
|
|
||||||
Reference in New Issue
Block a user