Developing with tmux

Tmux is a neat program that allows you to setup persisted sessions in your terminal.

It's useful for those people who:

So many terminals

The biggest benefit for me is to be able to setup environments for my development. If you walk by my desk it's not uncommon to see terminals everywhere. For example I will have one for my Rails server, Rails console, Spring server, Emacs (I boot mine from command line as i'm on WSL), Postgres etc

This is a bit of a pain to manage so I thought it was time to implement Tmux so I can script out my environment and set it up with one command.

After installing Tmux, I created the shell script below.


# Create a new Tmux session
tmux -2 new-session -d -s $SESSION

# Allow me to switch windows with Shift L/R Arrow like
# like my emacs setup
tmux bind -n S-Left  previous-window
tmux bind -n S-Right next-window

# Rails Development Server
tmux rename-window "Rails Dev Server"
tmux send-keys "rails s" C-m

# Spring Server for Fast Reloading
tmux new-window -n "Spring"
tmux send-keys "spring server" C-m

# Emacs
tmux new-window -n "emacs"
tmux send-keys "emacs" C-m

# Active
tmux new-window -n "Active"

tmux -2 attach-session -t $SESSION

It's easy to see what this is doing. Basically creating new 'windows' and starting up services with the 'send keys' command.

No Mouse?

Tmux seems to not play well with the mouse by default. I was unable to scroll up through my terminal which I always do. I rectified this by creating a ~/.tmux.conf file, and adding the below configuration.

set -g mouse on

It's early days but I've already found it really useful simply because all of my services are in the one spot and easy to manage. This is only scratching the surface of Tmux and I've found the documentation pretty extensive.