3061d27a12e19ccd249ff4e2d88b2a6bcadc46ee
CREATED, UPDATED, AUTHOR
| CREATED | UPDATED | AUTHOR |
|---|---|---|
| 2026-03-03 | 2026-03-03 | chawley |
TMUX Hack Session Launcher
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.
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.
Prerequisites
- tmux: Ensure
tmuxis 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.
Installation
- Copy the script to a directory in your
$PATH(e.g.,~/binor/usr/local/bin). - Rename it to something short, like
tm. - Make the script executable:
chmod +x ~/bin/tm
Usage
Run the script followed by the name of the pre-defined session:
tm mine
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.
Configuration
To add a new session, add a new case stanza inside the case $session in block.
Template
session_name)
if [[ $tcheck == 0 ]]; then
tmux -f "${TMUX_CONF}" new-session -d -s session_name
tmux -f "${TMUX_CONF}" rename-window 'initial_window'
tmux -f "${TMUX_CONF}" new-window -t:1 -n 'second_window' 'command_to_run'
fi
tmux attach-session -t session_name
;;
Script Variables
TMUX_CONF: Defaults to$HOME/.tmux.conf. Modify this variable if your configuration file is located elsewhere.
Description
Languages
Shell
100%