In this blog, we will setup and startup development environment using tmux and tmuxinator.
As tmuxinator is based on tmux, first we will take a look into tmux and its basic commands, then we will create yml templates for project setup.
Tmux introduction
Tmux stands for Terminal Multiplexer.
Using tmux you can create different windows and panes within one window of one terminal and move around these windows and panes.
It lets you switch between several programs inside one terminal, detach and reattach them to a different terminal at will.
Tmux installation
- Ubuntu:
sudo apt install tmux
- Windows: Using wsl for ubuntu`
- OSX:
brew install tmux
Open your terminal and start a tmux session by typing
tmux
This will open a tmux window.
Tmux Basic commands
- Create vertical pane: Ctrl + a + %
- Create horizontal pane: Ctrl + a + “
- Switch between panes: Ctrl + a + <- ->
- Close down pane: exit or Ctrl + a + x
Tmux window commands
- Create new window: Ctrl + a + c
- Switch between windows:Ctrl + a + n OR Ctrl + a + p
- Switch between windows: Ctrl + a + 0 OR Ctrl + a + 1
- Rename windows: Ctrl + a + ,
- Exit Windows:
exit
Tmux session commands
- View Tmux session:
tmux ls
- Start new session:
tmux new -s docker
- Rename session:
tmux rename-session -t 0 git
- Detach session: Ctrl + a + d
- Reattach session:
tmux attach -t 0
- Delete or kill session:
tmux kill-session -t docker
That's all the commands we need to get going with tmuxinator.
Tmuxinator
Tmuxinator is a tool that allows you to easily manage tmux sessions by using yaml files to describe the layout of a tmux session, and open up that session with a single command.
Installation: gem install tmuxinator
Tmuxinator commands
Create new template: Tmuxinator new <todo_project_name>
Edit existing template: Tmuxinator edit <project_name>
Start project: Tmuxinator start <project_name>
We have a sample rails project as backend and react project as frontend.
Usually for development purpose we need.
- editor
- rails server
- sidekiq server
- rails console
- git for rails project
- react npm start
- git for react project
We can create a predefined template using tmuxinator.
To start creating new project template in terminal: tmuxinator new <project name>
A editor is opened with yml file for project setup.
Give name to your project
name: todo
You need to define root of the project
root: ~/Documents/react-practice/todo-api
Then you can define you different windows are shown
and commands to execute in that window.
server: bundle exec rails s -p 4001
Above will create a window name server and start the rails server in the specified root folder.-
You can define panes in window which splits the screen
react_project: root: ~/Documents/react-practice/todo-app layout: even-horizontal panes: - npm start - git status
Above will create a window name react_project, change root folder for this window to react app then will start react server and git in 2 horizontal equally split panes.
A sample tmuxinator file for starting rails and react server.
name: todo root: ~/Documents/react-practice/todo-api windows: - editor: vim . - server: bundle exec rails s -p 4001 - sidekiq: bundle exec sidekiq - git: git status - rails_console: bundle exec rails console - react_project: root: ~/Documents/react-practice/todo-app layout: even-horizontal panes: - npm start - git status
To start the development setup using tmuxinator in terminal.
tmuxinator start todo
Tmux session for todo app with different windows and panes.
To close the todo app tmux session.
tmuxinator stop todo
Hope this will help you.
Thank you for reading
Top comments (0)