tmux
Productive Mouse-Free Development
by Brian P. Hogan
Version: P1.1 (March 12, 2012)
Copyright 2012 The Pragmatic Programmers, LLC. This book is licensed tothe individual who purchased it. We don't copy-protect itbecause that would limit your ability to use it for yourown purposes. Please don't break this trustyou can use this across all of your devices but please do not share this copywith other members of your team, with friends, or via file sharing services. Thanks.
Dave & Andy.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and The Pragmatic Programmers, LLC was aware of a trademark claim, the designations have been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes no responsibility for errors or omissions, or for damages that may result from the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create better software and have more fun. For more information, as well as the latest Pragmatic titles, please visit us at http://pragprog.com.
Table of Contents
Copyright 2012, The Pragmatic Bookshelf.
Acknowledgments
This book started out as something Id planned to self-publish, but working with the fine folks at the Pragmatic Bookshelf has always been such a great experience that I decided to see if they would work with me again. Im so grateful to Dave and Andy for letting me work with them again.
Thanks to my awesome editor, Susannah Pfalzer, the book youre reading is in much better shape. Her guidance was essential in keeping things focused, on track, and readable.
The folks that volunteered their time to review this book provided some of the most interesting and thoughtful comments Ive seen. Thanks to them, this book has a bunch of wonderful ideas, too. Thanks so much to Jeff Holland, Austen Ott, Kevin Gisi, Tony Collen, Charley Stran, Chris Johnson, Drew Neil, Darcy Laycock, Luke Chadwick, Jeff Carley, Marc Harter, and Nick LaMuro for the great suggestions.
Special thanks to Chris Warren, Mike Weber, Aaron Godin, Emma Smith, Erich Tesky, and the rest of my business associates for their support, and to Chris Johnson for getting me hooked on using tmux in the first place.
Finally, Im extremely grateful for the continued support of my wife Carissa, who works hard to wrangle our daughters so I can carve out time to write.
Copyright 2012, The Pragmatic Bookshelf.
Preface
Your mouse is slowing you down.
The mouse, when introduced, created a new way for us to interact with our computers. We could click, double-click, triple-click, and now even swipe to interact with our applications. The mouse, along with graphical interfaces, made computers just a little easier to use for average users. But theres a downside to the mouse, especially for programmers.
As we build software, we work with multiple programs throughout the course of our day. A web developer, for example, might have a database console, web server, and a text editor running at the same time. Switching between these with the mouse eats up valuable time and can break your focus. It may not seem like much, but moving your hand off of the keyboards home row, placing it on the mouse, locating the pointer, and performing the task can be pretty distracting.
Using tmux, you can create an environment like the one shown in Figure 1, . Using tmuxs windows, you can easily manage the text editor, the database console, and the local web server within a single environment. And you can split tmux windows into sections, so multiple apps can run side by side. This means you can run a text-based browser, IRC client, or your automated tests in the same window as your main editor.
Best of all, you can quickly move between these windows and panes using only the keyboard, which will greatly increase both your concentration and your productivity.
Figure 1. tmux as a development environmentIn this book, youll learn how to configure, use, and customize tmux. Youll learn how to manage multiple programs simultaneously, write scripts to create custom environments, and find out how to use tmux to work remotely with others. With tmux, you can create a work environment that keeps almost everything you need at your fingertips.
What Is tmux?
tmux is a terminal multiplexer . It lets us use a single environment to launch multiple terminals, or windows, each running its own process or program. For example, we can launch tmux and load up the Vim text editor. We can then create a new window, load up a database console, and switch back and forth between these programs all within a single session.
If you use a modern operating system and a terminal that has tabs, this doesnt sound like anything new. But running multiple programs simultaneously is only one of tmuxs features. We can divide windows into horizontal or vertical panes, which means we can run two or more programs on the same screen side by side. And we can do it all without using the mouse.
We can also detach from a session, meaning we can leave our environment running in the background. If youve used GNU-Screen before, youre familiar with this feature. In many ways, tmux is like GNU-Screen with a lot of extra features, and a much simpler configuration system. And since tmux uses a client-server model, we can control windows and panes from a central location, or even jump between multiple sessions from a single terminal window. This client-server model also lets us create scripts and interact with tmux from other windows or applications.
Over the course of this book, well explore all of these features and more.
Who Should Read This Book
This book aims to help application developers who work on OS X or Linux operating systems and spend a good part of their time using the terminal.
If youre a software developer, youll see how to use tmux to build a development environment that can make working with multiple terminal sessions a breeze. And if youre already comfortable using Vim or Emacs, youll see how tmux can accelerate your workflow even more.
If youre a system administrator or a developer who spends some time working with remote servers, youll be interested in how you can leverage tmux to create a persistent dashboard for monitoring servers.
Whats In This Book
This book will show you how to incorporate tmux into your work by taking you through its basic features and showing you how you might apply them to everyday situations.
In Chapter 1, , youll learn about the basic features of tmux as you create sessions, panes, and windows and learn how to perform basic navigation.
In Chapter 2, , youll learn how to redefine many of the default keybindings and the appearance of tmux.
In Chapter 3, , youll see how to script your own development environment using the command-line interface, configuration files, and the tmuxinator program.
After that, youll work with text in Chapter 4, . Youll see how to use keyboard keys to move backwards through the buffer, how to select and copy text, and how to work with multiple paste buffers.