Originally published on 2026-02-01
Original article (Japanese): tmux-try: tryとtmuxを繋いで実験ディレクトリを即セッション化する
Have you ever found yourself saying, "I want to try something, so I'll create a new directory and start tmux..."?
Previously, I introduced try (for more details, see "try: Can You Find the Inspiration from 2 AM the Next Morning?"), a handy tool for managing experiment directories with date prefixes. However, starting a tmux session from there was a separate task. To bridge these two, I created tmux-try.
The Problem tmux-try Solves
After creating an experiment directory with try, I used to follow these steps every time:
# Create and move to the directory with try
try redis-test
# Check if a tmux session exists
tmux list-sessions | grep redis-test
# If it exists, attach to it
tmux attach-session -t redis-test
# If not, create a new one
tmux new-session -s redis-test
It was a bit tedious to have to type different commands based on whether a session existed or not. tmux-try consolidates this into a single command.
# Just this one command
tmux-try redis-test
Key Features
1. Path-Based Sessions
If you specify an explicit path (starting with ./, ~/, or /), a session will start in that directory.
# Under the current directory
tmux-try ./myproject
# Under the home directory
tmux-try ~/projects/myapp
# Absolute path
tmux-try /absolute/path/to/project
If the directory does not exist, it will be created automatically.
2. Name-Based Sessions (Integration with try)
If there is no path prefix, the fuzzy finder from try will launch.
# Search for existing experiments or create a new one
tmux-try redis
# Start interactively without arguments
tmux-try
If try is not installed, it will start a session in the current directory.
3. Clone GitHub Repositories and Start Sessions
If you pass a Git URL, it will clone using try and immediately start a session.
# Clone via HTTPS
tmux-try https://github.com/tobi/try
# Clone via SSH
tmux-try git@github.com:user/repo.git
The clone destination will be created with a date prefix, like ~/src/tries/2026-01-31-tobi-try/.
4. Automatic Detection of tmuxinator
If tmuxinator is installed, it will automatically create and use a .tmuxinator.yml.
name: myproject
root: /path/to/myproject
windows:
- main:
panes:
- zsh
- opencode
In environments without tmuxinator, it will fall back to using plain tmux commands.
Argument Resolution Rules
tmux-try automatically determines what action to take based on the format of the arguments.
| Argument | Determination | Action |
|---|---|---|
./foo, ~/foo, /foo
|
Path prefix | Use as a directory |
https://..., git@...
|
Git URL | Clone with try |
foo |
Name only | tmuxinator project → try experiment |
| (none) | Empty | try selector → current directory |
Installation
Prerequisites
- tmux: Terminal multiplexer (required)
- try: Experiment directory manager (needed for name-based sessions)
- bash: Shell (version 4.0 or later)
Optional
- tmuxinator: tmux session manager (used automatically if available)
Steps
- Download the script
curl -sL https://raw.githubusercontent.com/tumf/tmux-try/main/tmux-try \
-o /usr/local/bin/tmux-try
- Grant execute permissions
chmod +x /usr/local/bin/tmux-try
- Install try (recommended)
gem install try-cli
eval "$(try init)" # Add to .zshrc or .bashrc
- Set up an alias (recommended)
# Add to .zshrc or .bashrc
alias t='tmux-try'
You can start an experiment environment with just t redis. It's a single character, so you can execute it the moment you think of it.
Design Decisions
Why tmuxinator is Not Required
While tmuxinator is convenient, I made it optional for the following reasons:
- Reduce environmental dependencies: It works with just tmux.
- Lightweight: Usable in environments without Ruby installation.
- Flexibility: Only those who want to use tmuxinator's settings can do so.
In the implementation, the presence of tmuxinator is detected with command -v tmuxinator, and it automatically falls back.
if command -v tmuxinator &> /dev/null; then
# Use tmuxinator
tmuxinator start "$project_name"
else
# Use plain tmux
tmux new-session -s "$session_name" -c "$directory"
fi
Integration with try
try is a tool specifically designed for "experiment directory management" (for more details, see "try: Can You Find the Inspiration from 2 AM the Next Morning?"). It has features for automatic naming with date prefixes, fuzzy searching, and time-aware sorting, managing the entire lifecycle of experiments.
tmux-try respects this philosophy and is designed to directly utilize try's features. It does not implement its own directory management but delegates that to try.
Usage Examples
Case 1: Starting a New Experiment
# Launch the fuzzy finder from try
tmux-try
# Filter with "redis" and create a new one
# → Move to ~/src/tries/2026-01-31-redis/ and start the session
Case 2: Trying a GitHub Repository
# Clone the repository and immediately start a session
tmux-try https://github.com/tobi/try
# → Start the session in ~/src/tries/2026-01-31-tobi-try/
Case 3: Working on an Existing Project
# Start an existing tmuxinator project
tmux-try myproject
# Or specify an explicit path
tmux-try ~/projects/myproject
Conclusion
tmux-try is a simple wrapper that connects try and tmux.
Key Benefits:
- One command to complete: Automates directory creation → movement → session start.
- Flexible argument resolution: Automatically determines paths, names, and Git URLs.
- Environment adaptability: Automatically detects the presence of tmuxinator and falls back.
It's a tool that allows you to quickly transform a fleeting thought of "I want to try this" into an execution environment. If you're interested, give it a try!
Top comments (0)