Tmux Sessionizer is a Bash script inspired by the Primeagen that automates the creation and management of Tmux sessions based on a user-defined configuration file. It allows you to quickly set up and switch between Tmux sessions, including specific directories, windows, and commands.
- Automatically create Tmux sessions based on a configuration file (
sessionizer.config.yaml). - Supports multiple search paths for project directories.
- Automatically finds project directories containing
.gitor.session.config.yaml. - Configurable session windows and scripts.
- Supports FZF for quick selection of project directories.
- Automatically sets up Tmux session windows and runs setup scripts.
- Tmux: Make sure Tmux is installed and available in your
$PATH. - yq: This script relies on
yqto parse YAML configuration files. Install it using:# Install yq (choose the appropriate installation method for your OS) # For example, using Homebrew on macOS: brew install yq
- fzf: The script uses
fzffor fuzzy finding. Install it using:# Install fzf (choose the appropriate installation method for your OS) # For example, using Homebrew on macOS: brew install fzf
zshbashMore coming soon!
You can install the tmux-sessionizer with the following commands:
# For people on bash:
curl -sS https://raw.githubusercontent.com/BriHan-Tech/tmux-sessionizer/refs/heads/master/install.sh | bash
# For people on zsh:
curl -sS https://raw.githubusercontent.com/BriHan-Tech/tmux-sessionizer/refs/heads/master/install.sh | zshThis will install the sessionizer script in the ~/.tmux/scripts/ directory.
Then, it will bind the script to Ctrl + f
Note: If your user does not have permission, you will need:
curl -sS https://raw.githubusercontent.com/BriHan-Tech/tmux-sessionizer/main/install-sessionizer.sh | sudo <your-shell> You can set up keyboard shorcuts to tmux-sessionizer by using the sessionizer alias.
For instance, I bound Ctrl + f to start the sessionizer:
bindkey -s ^f "sessionizer\n"The sessionizer alias will launch tmux-sessionizer!
The script searches for project directories containing .git or .session.config.yaml files within the specified search paths defined in the sessionizer.config.yaml file. It uses fzf for fuzzy selection, allowing you to quickly choose the desired project directory.
By default, the script looks for a configuration file at ~/.config/tmux/sessionizer.config.yaml. You can override this location and file name by setting the TMUX_SESSIONIZER environment variable.
Example sessionizer.config.yaml:
search_paths:
paths:
- "~/projects"
- "~/work"
mindepth: 1
maxdepth: 3Each project directory can contain a .session.config.yaml file to define session-specific configurations:
Example .session.config.yaml:
name: my_project
directory: ~/projects/my_project
setup_script:
- source venv/bin/activate
- npm install
windows:
- name: editor
directory: ~/projects/my_project
script:
- vim
- name: server
directory: ~/projects/my_project
script:
- npm start- The script checks if
yqis installed. - It loads the sessionizer configuration (
sessionizer.config.yaml) to get search paths. - It searches for directories containing
.gitor.session.config.yamlfiles. - It prompts you to select a directory using
fzf(if not provided as an argument). - It creates a new Tmux session with the name and directory specified in
.session.config.yamlor defaults to the directory name. - It sets up the Tmux session windows, runs setup scripts, and attaches or switches to the session.
- The script supports window scripts and session setup scripts defined in
.session.config.yaml. - If a session already exists with the same name, the script will switch to that session instead of creating a new one.
- Major Refactorings~
- Support for configuring Tmux panes within windows.
This project is licensed under the MIT License.