A lightning-fast tmux session manager that simplifies project workflows with automatic environment configuration.
tmux-sessionizer
is a powerful Bash utility designed to streamline tmux workflow by:
- Quickly switching between projects
- Automatically creating consistent session layouts
- Providing project-specific environment configuration
- Eliminating repetitive setup tasks
The tool consists of two components:
tmux-sessionizer
- The main script for creating and switching sessions.tmux-sessionizer
- A project-specific configuration script
- tmux 3.0+
- Bash 4.0+ or Zsh
- fzf (for interactive directory selection)
- fd (optional, for faster directory scanning)
# Create bin directory if it doesn't exist
mkdir -p ~/.local/bin
# Download the script
curl -o ~/.local/bin/tmux-sessionizer https://raw.githubusercontent.com/thenameiswiiwin/tmux-sessionizer/main/tmux-sessionizer
# Make it executable
chmod +x ~/.local/bin/tmux-sessionizer
# Ensure ~/.local/bin is in your PATH
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc # or ~/.bashrc
# Download the configuration script
curl -o ~/.tmux-sessionizer https://raw.githubusercontent.com/thenameiswiiwin/dev-env/develop/.tmux-sessionizer
# Make it executable
chmod +x ~/.tmux-sessionizer
Add to your .zshrc
or .bashrc
:
# Add Ctrl+f shortcut for tmux-sessionizer
if command -v tmux-sessionizer &>/dev/null; then
bindkey -s "^f" "tmux-sessionizer\n" # Zsh
# OR
# bind -x '"\C-f":"tmux-sessionizer"' # Bash
fi
- Interactive: Press
Ctrl+f
or runtmux-sessionizer
with no arguments - Direct path:
tmux-sessionizer ~/dev/myproject
- Switch projects: Press
prefix + f
(typicallyCtrl+a f
) within tmux - Create windows: Standard tmux commands after session is created
- Directory Selection: Choose a project directory
- Session Creation: Creates tmux session named after directory
- Layout Configuration: Automatically sets up project-specific windows
- Environment Hydration: Sources
.tmux-sessionizer
for custom setup
Create a .tmux-sessionizer
file in your project root for custom setup:
#!/usr/bin/env bash
# Project-specific setup goes here
echo "Setting up custom project environment..."
# Add commands to run in the session
# Example: Starting development server in a window named "server"
if tmux has-session -t "$(tmux display-message -p '#S'):server" 2>/dev/null; then
tmux send-keys -t "$(tmux display-message -p '#S'):server" "npm run dev" C-m
fi
The .tmux-sessionizer
script automatically detects project types and creates appropriate window layouts:
Project Type | Detection Method | Windows Created |
---|---|---|
Node.js | package.json | edit, shell, server, test |
Go | go.mod | edit, shell, run, test |
Rust | Cargo.toml | edit, shell, build, test |
PHP | composer.json | edit, shell, server, test |
Python | requirements.txt | edit, shell, run, test |
Generic | (fallback) | edit, shell |
The .tmux-sessionizer
script provides several helper functions:
- window_exists: Check if a window exists in a session
- create_window_if_missing: Create a window if it doesn't exist
- send_command: Send a command to a specific window
You can create project-specific layouts by modifying the .tmux-sessionizer
file:
#!/usr/bin/env bash
# Skip for home directory
if [[ "$PWD" == "$HOME" ]]; then
return 0
fi
# Create a custom layout
session_name=$(tmux display-message -p '#S')
# Create windows
tmux new-window -t "$session_name" -n "database"
tmux new-window -t "$session_name" -n "logs"
# Set up commands
tmux send-keys -t "$session_name:database" "docker-compose up -d db" C-m
tmux send-keys -t "$session_name:logs" "tail -f logs/development.log" C-m
# Return to edit window
tmux select-window -t "$session_name:edit"
The .tmux-sessionizer
script respects your tmux theme settings (dark/light mode). To toggle themes, press prefix + T
.
Issue: tmux-sessionizer not found Solution: Ensure ~/.local/bin is in your PATH and the script is executable
Issue: Session not created Solution: Check for error messages during session creation
Issue: Windows not being created Solution: Verify that tmux is properly installed and the session name is valid
Issue: Custom configuration not being loaded
Solution: Check that .tmux-sessionizer
is executable and contains valid Bash syntax
For faster operation:
- Install
fd
for faster directory scanning - Minimize file operations in your
.tmux-sessionizer
file - Use efficient window creation patterns
- Avoid unnecessary commands in the script
Modify the tmux-sessionizer
script to search different directories:
# Find in custom locations
selected=$(find ~/work ~/clients ~/experiments -mindepth 1 -maxdepth 1 -type d | fzf)
Add support for additional project types in .tmux-sessionizer
:
# Laravel project
if [[ -f "$git_root/artisan" ]]; then
echo "Setting up Laravel project environment"
setup_project_windows "$session_name" "$git_root" "shell" "artisan" "routes" "test"
fi
- Fast Project Switching: Use
Ctrl+f
outside tmux orprefix + f
inside - Quick Command Execution: Use tmux send-keys for automating common tasks
- Multiple Monitors: Create separate sessions for different displays
- Session Persistence: tmux sessions remain after disconnect; reattach later
- Original concept by ThePrimeagen