Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Getting Started with tmux
Getting Started with tmux

Getting Started with tmux: Maximize your productivity by accessing several terminal sessions from a single window using tmux

eBook
R$80 R$133.99
Paperback
R$167.99
Subscription
Free Trial
Renews at R$50p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Getting Started with tmux

Chapter 2. Configuring tmux

Now that we've had our first taste of tmux, let's dig into our first topic in greater detail. tmux is a very powerful program and thankfully one that is also highly configurable. You can change almost anything about its behavior, from the way it looks and feels to the commands it executes on load; you can even configure every key combination to which tmux responds.

In this chapter, we will cover various ways to configure tmux to customize and optimize it for your workflow. We will build a sample configuration that can be used to make tmux a bit cleaner, prettier, and more useful.

We will be unable to cover every minute detail or configuration option, but we will hit the most common ones and set you up with the knowledge and toolset to be able to tackle any configuration you desire. In this chapter, we will discuss the following:

  • Using the set-option command
  • Creating a tmux configuration file
  • Emacs or vi mode
  • Enabling mouse modes
  • Changing the status...

Using the set-option command

The main way in which options are set and configured within tmux is through the appropriately named set-option command.

This command can be called on its own to set an option temporarily. However, most of the time, we will use it to set options within a tmux configuration file so each time we launch tmux, the options are set the way we would like.

For a taste of using the set-option command to set an option temporarily, open a terminal window and launch tmux; alternatively, if you've been following along through Chapter 1, Jump Right In, just type the following command in the window:

$ tmux set-option status off

Once you do this, the status bar will disappear! This setting is only temporary, so if you leave it as is, end the session, and restart tmux or create a new session, it will not load this setting. In other words, a status bar will appear.

What you have done is that you've told tmux to set the option status to a value of off. You can use this command...

Creating a tmux configuration file

In order to keep the settings around after restarting tmux, we will create a configuration file that will include all the information about what options we want to set and to what values.

Like many other Unix-based utilities, configuring tmux is as simple as creating a file with the name .tmux.conf in your home directory.

However, unlike many other configuration files, a tmux configuration file does not contain some kind of specific configuration language for the program, rather it consists of a series of tmux commands that are run, in order, when tmux starts up. Most of the commands we'll see are simple set-option commands similar to the commands we played with in the previous examples. Let's create and start building our configuration file:

$ cd ~
$ touch .tmux.conf

Open this newly created file in your favorite text editor and we're ready to rock!

Tip

Like with most Unix-based utilities, this file in your personal directory contains the configuration...

Emacs or vi mode

As we discovered in Chapter 1, Jump Right In, tmux tries to help developers by providing two sets of key bindings, one each for the two most widespread text editors. If you swing one way or the other, this is likely to be one of the first things you'll want to change to make tmux feel right for you.

The default for tmux is to use the Emacs mode keys, so if you are an Emacs user, you may be all set. tmux also tries to help out and might, based on environment variables, switch to one group or the other by default. To check which mode tmux is currently in, run the following command:

$ tmux show-options -g | grep key

You should get an output that looks something similar to the following command:

$ status-keys emacs

If you are in the mode you'd like to be in, you can do nothing. If you are in the wrong mode though, you would most likely want to add the following couple of lines to your .tmux.conf file, obviously choosing the appropriate editor:

set-option -g status-keys...

Enabling mouse modes

First, it's worthwhile to note that one of the main benefits of tmux is to obviate the need to reach for your mouse as often as you otherwise would. So, some purists would balk at the notion of enabling mouse modes for tmux.

That said, it is often rather convenient to use the mouse to scroll, select text, resize panes, choose an option from a list, and more. And yes, tmux allows you to do all of that with the mouse. These features are disabled by default so to enable them, we need to add the following lines to our .tmux.conf (either Emacs or vi):

set-window-option -g mouse-mode on
set-option -g mouse-select-window on
set-option -g mouse-select-pane on
set-option -g mouse-resize-pane on

This will enable mouse functionality in all of the ways we described. We haven't yet dealt with panes, but when we touch on that in Chapter 3, Sessions, Windows, and Panes, it will be more apparent how using the mouse to resize them will be incredibly convenient.

Using the set-option command


The main way in which options are set and configured within tmux is through the appropriately named set-option command.

This command can be called on its own to set an option temporarily. However, most of the time, we will use it to set options within a tmux configuration file so each time we launch tmux, the options are set the way we would like.

For a taste of using the set-option command to set an option temporarily, open a terminal window and launch tmux; alternatively, if you've been following along through Chapter 1, Jump Right In, just type the following command in the window:

$ tmux set-option status off

Once you do this, the status bar will disappear! This setting is only temporary, so if you leave it as is, end the session, and restart tmux or create a new session, it will not load this setting. In other words, a status bar will appear.

What you have done is that you've told tmux to set the option status to a value of off. You can use this command to set...

Creating a tmux configuration file


In order to keep the settings around after restarting tmux, we will create a configuration file that will include all the information about what options we want to set and to what values.

Like many other Unix-based utilities, configuring tmux is as simple as creating a file with the name .tmux.conf in your home directory.

However, unlike many other configuration files, a tmux configuration file does not contain some kind of specific configuration language for the program, rather it consists of a series of tmux commands that are run, in order, when tmux starts up. Most of the commands we'll see are simple set-option commands similar to the commands we played with in the previous examples. Let's create and start building our configuration file:

$ cd ~
$ touch .tmux.conf

Open this newly created file in your favorite text editor and we're ready to rock!

Tip

Like with most Unix-based utilities, this file in your personal directory contains the configuration for...

Emacs or vi mode


As we discovered in Chapter 1, Jump Right In, tmux tries to help developers by providing two sets of key bindings, one each for the two most widespread text editors. If you swing one way or the other, this is likely to be one of the first things you'll want to change to make tmux feel right for you.

The default for tmux is to use the Emacs mode keys, so if you are an Emacs user, you may be all set. tmux also tries to help out and might, based on environment variables, switch to one group or the other by default. To check which mode tmux is currently in, run the following command:

$ tmux show-options -g | grep key

You should get an output that looks something similar to the following command:

$ status-keys emacs

If you are in the mode you'd like to be in, you can do nothing. If you are in the wrong mode though, you would most likely want to add the following couple of lines to your .tmux.conf file, obviously choosing the appropriate editor:

set-option -g status-keys emacs
set...

Enabling mouse modes


First, it's worthwhile to note that one of the main benefits of tmux is to obviate the need to reach for your mouse as often as you otherwise would. So, some purists would balk at the notion of enabling mouse modes for tmux.

That said, it is often rather convenient to use the mouse to scroll, select text, resize panes, choose an option from a list, and more. And yes, tmux allows you to do all of that with the mouse. These features are disabled by default so to enable them, we need to add the following lines to our .tmux.conf (either Emacs or vi):

set-window-option -g mouse-mode on
set-option -g mouse-select-window on
set-option -g mouse-select-pane on
set-option -g mouse-resize-pane on

This will enable mouse functionality in all of the ways we described. We haven't yet dealt with panes, but when we touch on that in Chapter 3, Sessions, Windows, and Panes, it will be more apparent how using the mouse to resize them will be incredibly convenient.

Changing the status bar


We learned a bit about the status bar in the last chapter when we discussed changing the session and window names. This status bar is highly customizable, and it's a great place to start learning about configuring tmux. We can change the status bar colors, what appears on the status bar, the alignment, and much more.

Modifying the background color of the status bar

Let's add an item to our configuration to change the color of the status bar. As we saw by jumping in, the default color of the status bar is a shade of green. Note that there happens to be a shade of green in our configuration as well, but it is likely a different color on your terminal unless you are using the same color scheme as we are.

Note

The authors are using a color scheme called Solarized. It is a color scheme that includes both dark and light variants and is optimized for the terminal and readability. It was developed by Ethan Schoonover and has gained quite a following in the tech community for...

Binding keys


Binding keys will allow you to change the keys and key combinations that tmux will recognize for any command. This also allows us to create new key combinations for existing commands or change the key binding for any existing keys used by tmux. It even lets you assign new key bindings to any command we can dream about.

The commands to which we can bind keys can even prompt for user input. There is no constraint on uniqueness, so we could bind multiple keys to issue the same command or bind no keys for a particular command.

What this all means is that while there is not an existing key combination available to reload the tmux source file, we can make up our own key combination and assign it to the rather lengthy source-file command so we don't have to type the whole thing each time we want to reload the configuration.

First, let's find a good key combination to bind for this command.

Viewing current bindings

Recall from the first chapter that we were able to see all of the current...

Unbinding keys


Now let's say there is a key binding that you want to remove for some reason. This is very easy; just add an unbind directive to your .tmux.conf file.

Say we wanted to unbind 0 from its default action of selecting window 0 for some reason. To do this, simply add the following code snippet to your configuration:

unbind 0

Note that there is no need to explicitly unbind a key before binding it to something else; every key can only have one binding. So, we find it rather rare to use this bit of utility, but it's nice to know it's there when you need it.

Status bar revisited


Last time we touched the status bar, we altered its colors, but we did not do anything to change its content. tmux allows us to change a lot of different aspects of the content of the status bar. We won't have an in-depth look at every possible configuration, but will explain the concept and show one example.

So, the status bar has three chunks basically:

  • status-left: This represents the stuff on the status bar on the left-hand side, including the current session

  • List of open windows: This appears in the middle by default

  • status-right: This represents the stuff on the status bar on the right-hand side, including the current date

Recall our status bar, which appears as shown in the following screenshot:

By default, status-left shows the name of the current session in brackets. We named our session tutorial, so status-left for us is [tutorial].

We can change these. They are just simple strings with some magic character pairs that tmux fills in based on what they mean. For...

Option types


Thus far, all of the options we have set had the -g flag. This means that the option applies globally. However, there are three types of options: server options, session options, and window options.

There are also multiple flags that indicate how a given option should affect or be affected. This sounds complex, but it's rather simple.

A server option will apply to any client that connects to tmux. Under the hood, when you type and run the tmux command the first time, tmux creates a server; then, it creates your client and connects to the server it started. This is the magic that allows you to detach your session, reattach it later, and have everything running as you left it because the tmux server keeps chugging in the background. So an option specified with the -s flag will apply to the server, meaning it will affect any clients that attach to it.

A session option will apply to the current session. This means that two clients could connect to the same server and each could have...

Left arrow icon Right arrow icon

Description

The book is intended for software developers, DevOps engineers, and other professionals who make heavy use of the terminal in their daily workflow. Some familiarity with the terminal is useful but no prior experience with tmux or other terminal multiplexers (such as GNU Screen) is required.

What you will learn

  • Increase productivity by using tmux rather than a mouse to switch between terminal windows
  • Persist sessions on remote machines over SSH with tmux, making it easy to resume right where you left off even if your connection is terminated
  • Learn how tmux can be used to create persistent dashboards for monitoring servers
  • Use tmux to manage multiple terminal windows from a single one
  • Maximize terminal productivity with tmux
  • Maintain the state even when a terminal window is closed with tmux
  • Configure tmux and customize it for your needs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Sep 24, 2014
Length: 148 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985173
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : Sep 24, 2014
Length: 148 pages
Edition : 1st
Language : English
ISBN-13 : 9781783985173
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
R$50 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
R$500 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts
R$800 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just R$25 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total R$ 713.97
Git Version Control Cookbook
R$272.99
SELinux Cookbook
R$272.99
Getting Started with tmux
R$167.99
Total R$ 713.97 Stars icon

Table of Contents

9 Chapters
1. Jump Right In Chevron down icon Chevron up icon
2. Configuring tmux Chevron down icon Chevron up icon
3. Sessions, Windows, and Panes Chevron down icon Chevron up icon
4. Manipulating Text Chevron down icon Chevron up icon
5. Diving Deeper Chevron down icon Chevron up icon
6. tmux for SSH, Pair Programming, and More Chevron down icon Chevron up icon
7. Using Other Tools with tmux Chevron down icon Chevron up icon
A. Appendix Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Most Recent
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(8 Ratings)
5 star 62.5%
4 star 12.5%
3 star 12.5%
2 star 12.5%
1 star 0%
Filter icon Filter
Most Recent

Filter reviews by




KS Sep 10, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
tmux は、単一の端末アプリを多重化して使う素晴らしいツールですが、あまりいい解説がありませんでした。テキスト中心で、表示がどうなっているのか、使っている概念が何なのか、想像するのが難しかったのですが、このあたりがスクリーンショットを使ってわかりやすく解説してあります。
Amazon Verified review Amazon
Daniel Demuth Jul 26, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is a nice introduction to tmux, it explains in clear words and can be understood easily. While I am a retired IT guy I did not know tmux at all.
Amazon Verified review Amazon
Andrew C. Dec 17, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
If you are looking for a concise book then this is not for you. The author has a tendency to tell you the important bits after you need to know them. On the positive side, having filtered out the verbiage, there is some good stuff in the book.
Amazon Verified review Amazon
Jerome Lanteri Jul 27, 2017
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
That book is to short.Also it doesn't speak about option -t and group sessions (lake of information then ?).So if you reduce the number on pages by just the real content without borring and uninteresting pictures, you can divide the number of pages by 2 ou 3 !!!Then this is an exepensive book for so little content.Also, when speak about tmuxinator (very quickly... 3 pages who can be write in one or half one...Why not give the list of all the command you should use for config a pretty good personnalized session ?ok... i think that the autor was very lazy.I regret to buy this book.ALSO kindle format is not full implemented... you can not jump on page through an index... incredible.
Amazon Verified review Amazon
Kquinn03 Dec 12, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Most understandable, easy to follow TMUX programming how to I've ever seen.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.