Switching project is a chore. I work on multiple projects that require different sets of commands to be run before starting to code. I got tired of remembering each command and running it one by one. I resolved this problem with tmuxinator. Now I just run tmuxinator [project]
and it automatically runs all the commands I need to run for a project.
The problem I had
When switching projects, I usually run something similar to the following before starting to code.
cd [docker-path]
docker compose up
cd [node-project-path]
nvm use [node-version]
npm run dev
cd [java-project-path]
./gradlew run web:bootRun
I need to remember a lot of stuff when manually running each command.
- What is the command I need to run?
- Which path do I need to run the command in?
- What was the node version?
I made a few mistakes in the past, trying to run the right command. One of the worst one is running npm install
with a different node version. When I make that mistake, I usually run rm -rf node_modules; nvm use [node-version]; npm install
and all of that takes so much time to complete.
The solution
..is tmuxinator! Once I set up tmuxinator
, just running tmuxinator [project]
runs all of the commands in split windows. Just the way I like it! Problem solved!
I'll write how I set it up in the next section
Setting up tmuxinator
Installing the required Unix commands
The required Unix commands are the following.
I have a macOS so I ran these commands
brew install tmux
brew install tmuxinator
Configuring tmux
I just have a single configuration for tmux
, which is to enable mouse operations in tmux
.
# ~/.tmux.conf
set -g mouse on
This allowed me to
- switch panes with a click
- scroll in each pane
- skip learning
tmux
keybindings :D
Configuration tmuxinator
First I had to set the EDITOR
variable in the terminal in order to use tmuxinator
. In my case I was using zsh and I liked Vim, I put the following in the .zshrc
file.
export EDITOR=vim
Then you can run the following to make a tmuxinator
project.
tmuxinator new [project]
The editor will open with the default configuration. This is where you get excited and put all of the things you want tmuxinator
to do.
name: sample
root: /Users/gene/IdeaProjects/sample
windows:
- editor:
layout: even-vertical
panes:
- cd tools/docker; docker compose up
- cd admin-web/src/main/resources; nvm use 16.12 && npm run dev
- cd web/src/main/resources && nvm use 14.18 && npm run watch
- cd app && ./gradlew bootRun --args='--spring.profiles.active=local'
That's everything I did for configuring.
Run it!
Run the command tmuxinator sample
. You should see 4 panes get created and each pane will run the specified command. Now go make a tmuxinator
configuration for all of your projects!