tmux your local dev environment

Dec. 1, 2016

Web developers spend a lot of time in the terminal - each project requires at least one local server to be run, although typically both an ui server and an api server are needed. Add in a tab for a text editor, another one for running tests and yet another for git and the amount of terminal tabs balloons. Not to mention, restarting each server on every machine reboot, machine switch, or project switch becomes tedious. Tmux is used a lot on servers to share sessions between users, but it can also be used locally in tandem with tmuxinator and tmux-resurrect to manage this headache.

Tmux, a ‘terminal multiplexer’ allows multiple terminal windows to run within one, has tabs and splits within itself and allows sessions to be closed (:detach) and restarted (tmux attach-session -t session). Tumxinator is a ruby gem that allows tmux sessions to be configured using a yml file and then restored.

For example, this blog is a Jekyll generated static site; to contribute I would like to run the site locally and run guard for livereload. I would also like to run vim to compose my striking prose, and a miscellaneous terminal window for git.

After going through the basic tmuxinator setup, I would start a new tmuxinator project by running

$ mux edit softengblog

which will create a new yml file saved to ~/.tmuxinator/softengblog.yml. Then, I would configure my session:

name: softengblog
root: ~/repos/softeng

  - vim: vim
  - server:
      layout: tiled
        - sh
        - guard

Now running

$ mux softengblog

will start up the Jekyll site and my editor automatically.


A drawback to this approach however, is when the machine restarts the softengblog session goes back to a new session as described by the yml file; the previous state of the session is not restored. That’s where tmux-resurrect comes in. It is a tmux plugin that allows sessions to be saved with prefix-Ctrl+s and restored with prefix-Ctrl+r. tmux-resurrect and tmuxinator have overlapping usage, but having a tmuxinator config is still useful for sharing across machines/people, if you forget to save a session or if you would like to restart to the configured state.


Christine Yu, Software Developer
Software developer navigating the weird, wacky and ever changing world of JavaScript. Dreads winding bobbins, will eat dessert for dinner.