How I start working using Tmux
20 Jul 2015Introduction
These days with micro-services running and multiple dependencies “starting” work can be tricky.
For example: Just running Gogobot means running rails c
, rails s
, foreman
, spork
, ./read_pipe.sh
and sometimes even more.
Just getting to work in the morning or after a restart, just remembering everything you need to run can be difficult, and that’s just the main project, not counting in the chef repo, all microservices and more, well, you get the drift.
Since I am working on many projects at any given time, I always have a file in the root of the directory called start.sh
.
This way, when I want to start working on a project I just cd ~/Code/gogo && start.sh
.
This start.sh
script is simple bash that automates Tmux.
Here’s an example:
tmux new-session -d -s gogobot
tmux split-window -t gogobot:1 -v
tmux split-window -t gogobot:1.2 -h
tmux rename-window main
tmux send-keys -t gogobot:1.1 "vim ." "Enter"
tmux send-keys -t gogobot:1.2 "bundle exec rails c" "Enter"
tmux send-keys -t gogobot:1.3 "./read_pipe.sh" "Enter"
tmux new-window -t gogobot:2
tmux select-window -t gogobot:2
tmux rename-window server
tmux send-keys -t gogobot:2 "rm -f log/development.log && rm -f log/test.log && bundle exec rails server thin" "Enter"
tmux new-window -t gogobot:3
tmux select-window -t gogobot:3
tmux rename-window foreman
tmux send-keys -t gogobot:3 "bundle exec foreman start" "Enter"
tmux new-window -t gogobot:4
tmux select-window -t gogobot:4
tmux rename-window spork
tmux send-keys -t gogobot:4 "bundle exec spork" "Enter"
tmux new-window -t gogobot:5
tmux select-window -t gogobot:5
tmux rename-window proxy
tmux send-keys -t gogobot:5 "cd ~/Code/go/src/github.com/kensodev/go-solr-proxy/cmd/proxy && sh run_local_example.sh" "Enter"
tmux select-window -t gogobot:1
tmux attach -t gogobot
Explaining the parts
tmux new-session -d -s gogobot
will tell tmux to start a new session, detach from it and will name itgogobot
for reference in the future.tmux split-window -t gogobot:1 -v
will tell tmux to split window #1 in thegogobot
session and-v
means vertically.tmux split-window -t gogobot:1.2 -h
tells tmux to split pane2
in window1
and-h
as you probably already figured means horizontally.
Theres also
send-keys which is pretty self explanatory,
rename-window` and more.
I encourage you to read tmux reference, there are a lot of very useful tricks in there.
Final thoughts
You can see here, it’s pretty easy to automate your workflow around the terminal, I wrote about it some more in My development workflow (vim+tmux+terminal+alfred) Awesomeness.
It’s worth investing in automating your workflow, invest the time sharpening your skills and making your tools work better around your workflow.