From 87dbb4e498059ba262a746c0468c1695d88b445b Mon Sep 17 00:00:00 2001 From: "chawley (overlook)" Date: Sat, 21 Feb 2026 18:13:15 -0500 Subject: [PATCH 1/3] tmux-menu rewrite --- tmux-menu.template.sh | 131 ++++++++++++++++++++++++------------------ tmux-sessions.yaml | 22 +++++++ 2 files changed, 97 insertions(+), 56 deletions(-) create mode 100644 tmux-sessions.yaml diff --git a/tmux-menu.template.sh b/tmux-menu.template.sh index 491ed9f..d6b9459 100755 --- a/tmux-menu.template.sh +++ b/tmux-menu.template.sh @@ -1,22 +1,25 @@ #!/usr/bin/env bash #=============================================================================== # -# FILE: tmux-menu.sh -# -# USAGE: ./tmux-menu.sh -# -# DESCRIPTION: A hack script I wrote to help me manage pre-defined -# tmux-sessions -# -# OPTIONS: -# REQUIREMENTS: tmux -# NOTES: the cool down arrows in line 43? -v (see: digraphs) -# AUTHOR: C Hawley -# ORGANIZATION: -# CREATED: 2015-09 -# REVISION: Mon 16 Oct 2017 05:28:00 PM EDT +# CREATED : 2026-02-21 +# UPDATED : +# USAGE : +# DESC : Hack tmux session launcher. Reads a YAML file to create a tmux # session with multiple windows and commands. +# NOTES : +# 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 @@ -40,50 +43,66 @@ if [ ! -z $TMUX ]; then exit 1 fi -tcheck=$(tmux list-sessions | grep -c "${session}") # check if session is active -# if session is active, switch to it. If not active but part of the list below, -# create it. Finally, if no session or undefined session is passed, give an -# error message and list the active sessions +# if session is active, switch to it. +if tmux has-session -t "${session}" 2>/dev/null; then + echo "Session '${session}' already active. Attaching..." + tmux attach-session -t "${session}" + exit 0 +fi -# 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 rename-window 'localhost' # <- rename the first window (local) -# # ↓↓ define additional windows ↓↓ -# tmux new-window -t:1 -n 'lasis01' 'exec ssh lasis01' -# tmux new-window -t:2 -n 'lasis01dev' 'exec ssh lasis01dev' -# tmux new-window -t:3 -n 'ldssbox01' 'exec ssh ldssbox01' -# tmux new-window -t:4 -n 'lpdprod01' 'exec ssh lpdprod01' -# tmux new-window -t:5 -n 'ldatalake01' 'exec ssh ldatalake01' -# tmux new-window -t:6 -n 'lsandbox' 'exec ssh lsandbox' -# fi -# tmux attach-session -t analytics # <- if window active, switch to it -# ;; +# Check if the config file exists +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 "Usage: $(basename "$0") " + echo "Available Sessions from '${TMUX_CONFIG_FILE}':" + echo "---------------------------------------" + yq e '.sessions | keys | .[]' "${TMUX_CONFIG_FILE}" 2>/dev/null || echo "No sessions defined." + echo "" + echo "Active tmux Sessions:" + echo "---------------------" + tmux list-sessions 2>/dev/null || echo "No active sessions." + exit 1 +fi -case $session in - mine) - if [[ $tcheck == 0 ]]; then - tmux new-session -d -s mine - tmux rename-window 'local(aristotle)' - tmux new-window -t 1 -n 'root@vps' 'exec ssh root@vps.example.org' - tmux new-window -t:2 -n 'chawley@phaedrus' 'exec ssh chawley@phaedrus' - tmux new-window -t:3 -n 'chawley@homer' 'exec ssh chawley@homer.simpsons.net' - fi - tmux attach-session -t mine - ;; +echo "Creating new session '${session}' from '${TMUX_CONFIG_FILE}'..." - # add more sessions here inside a case stanza. Start with a session name and end with ';;' - - *) - echo "### ERROR No Such Session ###" - echo "Usage: tm " - echo "Active Sessions:" - echo "----------------" - tmux list-sessions - ;; -esac +# 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 Date: Sat, 21 Feb 2026 20:43:32 -0500 Subject: [PATCH 2/3] Changed name of config file --- tmux-menu.template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmux-menu.template.sh b/tmux-menu.template.sh index d6b9459..b5029bf 100755 --- a/tmux-menu.template.sh +++ b/tmux-menu.template.sh @@ -11,7 +11,7 @@ #=============================================================================== # Path to the YAML configuration file -TMUX_CONFIG_FILE="${HOME}/.config/tmux-menu/sessions.yaml" +TMUX_CONFIG_FILE="${HOME}/.config/tmux-menu/tmux-sessions.yaml" # Check for yq (YAML processor) if ! command -v yq &> /dev/null; then From 7c83a1154f0697d7884e9ebbf3580f46e506e1f6 Mon Sep 17 00:00:00 2001 From: "chawley (overlook)" Date: Sat, 21 Feb 2026 20:45:54 -0500 Subject: [PATCH 3/3] Copied over .tmux.conf from main branch --- .tmux.conf | 177 ++++++++++++++------------ tmux-menu.template.sh => tmux-menu.sh | 0 2 files changed, 95 insertions(+), 82 deletions(-) rename tmux-menu.template.sh => tmux-menu.sh (100%) diff --git a/.tmux.conf b/.tmux.conf index 8099fef..819387a 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -1,105 +1,118 @@ -## make tmux display things in 256 colors -## Getting italics working correctly in tmux -## https://unix.stackexchange.com/a/745718 -set -g default-terminal "tmux-256color" +######################################### +# Basic Settings and Prefix +######################################### -## set scrollback history to 10000 (10k) -set -g history-limit 10000 +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 -## set Ctrl-a as the default prefix key combination -## and unbind C-b to free it up -set -g prefix C-a -unbind C-b +######################################### +# Terminal and Display +######################################### -## 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!" -## map Vi movement keys as pane movement keys -bind h select-pane -L -bind j select-pane -D -bind k select-pane -U -bind l select-pane -R +# Window Management +bind Tab next-window # Cycle to the next window +bind , command-prompt "rename-window '%%'" # Open a prompt to rename the current window -# resize panes using PREFIX H, J, K, L -bind -r H resize-pane -L 2 -bind -r J resize-pane -D 2 -bind -r K resize-pane -U 2 -bind -r L resize-pane -R 2 +# Pane Management +bind | split-window -h # Split the current window horizontally +bind - split-window -v # Split the current window vertically -## PREFIX | to split horizontally -## PREFIX - to split vertically -bind | split-window -h -bind - split-window -v +# 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 -## shorten command delay -set -sg escape-time 1 +# 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) -## Tab through active windows -bind Tab next-window +######################################### +# Visual Notifications +######################################### -## Rename window -bind , command-prompt "rename-window '%%'" +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 -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 +######################################### +# Status Bar +######################################### -## ---------------------- -## set some pretty colors -## ---------------------- -## 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 +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 -## colorize messages in the command line -set-option -g message-style bg=colour0,fg=colour13 +# 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 -## set window list colors -setw -g window-status-style fg=colour8,bg=colour0 -setw -g window-status-current-style fg=colour2,bg=colour0,bright +# 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 -## Titles -set -g set-titles on -set -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name, active(or not) +# Status bar style +set-option -g status-style bg=#000000,fg=grey # Set the background to default (transparent), foreground color, and brightness -#set inactive/active window styles -# set -g window-style fg=colour0,bg=colour0 -# 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 +######################################### +# Pane Appearance +######################################### -## Status Bar: color -set-option -g status-style bg=colour0,fg=colour8,bright +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 -## Status Bar: Left - hostname -set -g status-left-length 70 -set -g status-left "#h" +######################################### +# Message Appearance +######################################### -## Status Bar: Right - Session name, Window & Pane, Date & Time -set -g status-right-length 60 -set -g status-right "S:#S W:#I P:#P | %Y-%m-%d %H:%M" +set-option -g message-style bg=default,fg=colour13 # Style for messages displayed in the tmux command line -# set window and pane index to 1 (0 by default) -set -g base-index 1 -setw -g pane-base-index 1 +######################################### +# Window Appearance +######################################### -## visual notification of activity in other windows -setw -g monitor-activity on -set -g visual-activity on +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 +######################################### -# ## use send-prefix to pass C-a through to application -# #bind C-a send-prefix -# -# ## Make the current window the first window -# bind T swap-window -t 1 -# -# set-option -g display-panes-active-colour colour2 -# set-option -g display-panes-colour colour1 -# +#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) diff --git a/tmux-menu.template.sh b/tmux-menu.sh similarity index 100% rename from tmux-menu.template.sh rename to tmux-menu.sh