71 lines
2.2 KiB
Markdown
71 lines
2.2 KiB
Markdown
---
|
|
CREATED : 2026-03-03
|
|
UPDATED : 2026-03-03
|
|
AUTHOR : 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 `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.
|
|
|
|
---
|
|
|
|
## Installation
|
|
|
|
1. Copy the script to a directory in your `$PATH` (e.g., `~/bin` or `/usr/local/bin`).
|
|
2. Rename it to something short, like `tm`.
|
|
3. Make the script executable:
|
|
```bash
|
|
chmod +x ~/bin/tm
|
|
```
|
|
|
|
---
|
|
|
|
## Usage
|
|
|
|
Run the script followed by the name of the pre-defined session:
|
|
|
|
```bash
|
|
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
|
|
```bash
|
|
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.
|