Intro to tmux
tmux is a terminal multiplexer, which basically means the author used a metaphor from electronics to make us all feel stupid. In all seriousness though, it means you can manage other processes from a single process, exactly like your regular terminal does. There are several great articles on tmux basics which I won’t cover here but if you’re unfamiliar with tmux, then I’d suggest first getting a gentle introduction. Throughout this article I’m going to mention some tmux commands, so if you don’t have tmux then grab it now so you can try them out:
Debian: $ sudo apt-get install tmux CentOS/Fedora: $ yum install tmux MacOS: $ brew install tmux Then check it’s installed by inspecting it’s version: $ tmux -V
The easiest way to fire up tmux is by running it with no arguments:
tmux. You get out of it by pressing
ctl-d or typing
exit to kill the tmux process.
1. Pause/Resume a terminal setup
Tmux is built with a client-server architecture, which means it actually runs a server in the background that ‘hosts’ your terminal session. Multiple clients are able to join this session. If you are using tmux on your local machine there isn’t too much you can do with this fact, except for keeping around your session for tomorrow if you’re one of those that never closes your terminal. I quite like closing everything at the end of the day but sometimes I have to stop in the middle of solving a problem and want to be able to retain this setup when I am available to complete the work.
Sure, you could minimize that terminal of yours, but it’s going to be sitting there, eating away at your subconscious, begging you to give it your limited precious attention when you’re home with your loved ones.
2. Templatize your terminal setup
Ever wonder if you could save the way you have set up your terminal and recreate those splits with one command? In tmux you can describe the tmux windows and panes when you start a session. I use
tmuxinator to do this. It’s a helpful tool that leverages tmux and makes it dead simple to make templates for each of my projects, grab it here: https://github.com/tmuxinator/tmuxinator.
tmuxinator project and run
tmuxinator start PROJECT in the morning to fire up your setup:
Here I’ve got a window with running application services, a window for my editor and a window for my tests. This is a great example of how tmux helps me focus more on my actual work and not my setup, which I appreciate. After all, I didn’t become a developer to set up laptops for development.
3. Run commands in context
I’m a huge believer in keeping around the larger context of what ever I am doing. I find it incredibly useful to be able to split a window, then start vim in the split so I can read some code while I’m running some long running operation. This is not exclusively a tmux feature but rather can be attributed to using a terminal based editor like vim or emacs along with tmux. This doesn’t mean you can’t use tmux if you don’t use a terminal based editor, all I’m saying is that they are a good match.
I often treat tmux panes as ephemeral and create and destroy them quite liberally based on what I’m busy with. I find this helps me manage the deep context of a programming task by running unrelated commands in separate windows.
4. Platform independent
You can use it on all major distros, as well as all the esoteric ones. This is nice because should you need it, you can feel at home on any system, which has happened to me before. When your laptop finally gives up (which it will), working on a temporary laptop is painstakingly tedious because of the friction caused by the unfamiliar setup. Using a tool that is available on all major desktop platforms will make you feel slightly more at home on your temporary laptop.
tmux’s interface is customizable, which allows you to change what appears in the tmux status bar, the general visuals of the interface and most importantly, the keyboard shortcuts. As a vim user, I have mapped navigation keys to the default vim
hjlk so I feel more comfortable navigating tmux windows and panes, something you simply can’t do in terminal emulators like iTerm and equivalents.
tmux customization used to be a little bit of a dark art. I used to find myself ‘tweaking’ my config everytime a new tmux version was released, but since the lovely tmux plugin manager landed on the scene, it’s dead simple to add plugins and keep them up to date with the latest changes in tmux itself. Having a plugin manager also allows you to easily reuse all the helpful tmux related goodness the community has put up on Github.
Last but not least, you can and save the tmux dotfiles (config files) online so you will never be without your trusty setup again.
I’ve written an entire article convincing you tmux is worth the effort. The truth is, it doesn’t really matter if you use it or not, what matters is that you attempt to reduce cognitive overhead in your day to day activities as a developer so you can focus on the real workTM. Think about what your dev setup looks like for a moment... how does it support or detract from your work as a developer?
Questions? I’d be humbled and happy to help.