๐พ Archived View for crm114.space โบ reading-list โบ 934f0a950e5fbe902d655724494740b3.gmi captured on 2023-01-29 at 16:02:06. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2023-01-29)
-=-=-=-=-=-=-
โฉ๏ธ Go back to the list of web bookmarks
โค โฅ โค โฅ โค โฅ โค โฅ โค โฅ โค โฅ
Nearly all my friends use tmux. I remember going out at night for drinks and the three of us would take a seat at a round table and take out our smart phones. This was back when phones still had physical รขยยQWERTYรขยย keyboards.
Despite our home computers being asleep or turned off, our usernames in the IRC channel we frequently visited persisted in the chatroom list. Our screens were lit by a kaleidoscope of colors on a black background. We sshรขยยd with ConnectBot into our cloud servers and reattached by running screen(1). As it hit 2AM, our Turkish coffee arrived, the |away status indicator trailing our online nicknames disappeared.
It was funny noticing, even though we knew each other by our real names, we sometimes opted to call each other by our nicks. Itรขยยs something about how personal relationships, formed online, persist in real life.
It seemed as if it were orchestrated, but each of us fell into the same ebb and flow of living our lives. No one told us to do it, but bit by bit, we incrementally optimized our lifestyles, personally and professionally, to arrive at destinations seeming eerily alike.
Like many things in life, when we act on autopilot, we sometimes arrive at similar destinations. This is often unplanned.
So, when I write an educational book about a computer application, I hope to write it for human beings. Not to sell you on tmux, convince you to like it or hate it, but to tell you what it is and how some people use it. Iรขยยll leave the rest to you.
About this book
Iรขยยve helped thousands learn tmux through my free resource under the name The Tao of tmux, which I kept as part of the documentation for the tmuxp session manager. And now, itรขยยs been expanded into a full-blown book with refined graphics, examples, and much more.
You do not need a book to use or understand tmux. If you want a technical manual, look at the manpage for tmux. Manpages, however, are rarely sufficient to wrap your brain around abstract concepts; theyรขยยre there for reference. This learning book is the culmination of years of explaining tmux to others online and in person.
In this book, we will break down tmux by its objects, from servers down to panes. It also includes a rehash of terminal facilities we use every day to keep us autodidacts up to speed with what is what. Iรขยยve included numerous examples of projects, permissively licensed source code, and workflows designed for efficiency in the world of the terminal.
tmux is a tool I find useful. While I donรขยยt attach it to my personal identity, itรขยยs been part of my daily life for years. Besides the original resource, Iรขยยve written a popular tmux starter configuration, a pythonic tmux library, and a tmux session manager.
popular tmux starter configuration
I am writing this from vim running in a tmux pane, inside a window, in a session running on a tmux server, through a client.
A word to absolute beginners: Donรขยยt feel you need to grasp the concepts of the command line and terminal multiplexing in a single sitting. You have the choice of picking out concepts of tmux you like, according to your needs or interests. If you havenรขยยt installed tmux yet, please view the Installation section in the Appendix of the book.
Follow @TheTaoOfTmux for updates or share on Twitter!
Styles
Formatted text like this is source code.
Formatted text with a $ in front is a terminal command. $ echo 'like this'. The text can be typed into the console, without the dollar character. For more information on the meaning of the รขยยdollar promptรขยย, check out What is the origin of the UNIX $ (dollar) prompt? on Super User.
origin of the UNIX $ (dollar) prompt?
In tmux, shortcuts require a prefix key to be sent beforehand. For instance, Prefix + d will detach a tmux client from its session. This prefix, by default, is <Ctrl-b>, but users can override it. This is discussed in greater detail in the prefix key section and configuration.
How this book is structured
First, anything involving installation and hard technical details are in the Appendix. A lot of books use installation instructions as filler in the early chapters. For me, itรขยยs more of not wanting to confuse beginners.
For special circumstances, like tmux on Windows 10, I decided adding screenshots is best, since many readers may be more comfortable with a visual approach.
Thinking in tmux goes over what tmux does and how it relates to the GUI desktops on our computers. Youรขยยll understand the big picture of what tmux is and how it can make your life easier.
Terminal Fundamentals shows the text-based environments youรขยยll be dealing with. Itรขยยs great for those new to tmux, but also presents technical background for developers, who learned the ropes through examples and osmosis. At the end of this section, youรขยยll be more confident and secure using the essential components underpinning a modern terminal environment.
Practical usage covers common bread-and-butter uses for you to use tmux immediately.
Server gives life to the unseen workhorse behind the scenes powering tmux. Youรขยยll think of tmux differently and may be impressed a client-server architecture could be presented to end users so seamlessly.
Sessions are the containers holding windows. Youรขยยll learn what sessions are and how they help organize your workspace in the terminal. Youรขยยll learn how to manipulate and rename and traverse sessions.
Windows are what you see when tmux is open in front of you. Youรขยยll learn how to rename and move windows.
Panes are a terminal in a terminal. This is where you get to work and do your magic! Youรขยยll learn how to create, delete, move between, and resize panes.
Configuration discusses customization of tmux and sets the foundation for how to think about .tmux.conf so you can customize your own.
Status bar and styling is devoted to the customization of the status line and colors in tmux. As a bonus, youรขยยll even learn how to display system information like CPU and memory usage via the status line.
Scripting tmux goes into command aliases and the advanced and powerful Targets and Formats concepts.
Technical stuff is a glimpse at tmux source code and how it works under the hood. You may learn enough to impress colleagues who already use tmux. If you like programming on Unix-like systems, this one is for you.
Tips and tricks wraps up with a whirlwind of useful terminal tutorials you can use with tmux to improve day to day development and administration experience.
Cheatsheets are organized tables of commands, shortcuts, and formats grouped by section.
Donations
If you enjoy my learning material or my open source software projects, please consider donating. Donations go directly to me and my current and future open source projects and are not squandered. Visit http://www.git-pull.com/support.html for ways to contribute.
http://www.git-pull.com/support.html
Formats
This book is available for sale on Leanpub and Amazon Kindle.
Itรขยยs also available to read for free on the web.
Errata
This is my first book. I am human and make mistakes.
If you find errors in this book, please submit them to me at tao.of.tmux nospam git-pull.com.
You can also submit a pull request via https://github.com/git-pull/tao-of-tmux.
https://github.com/git-pull/tao-of-tmux
I will update digital versions of the book with the changes where applicable.
Thanks
Thanks to the contributors for spotting errors in this book and submitting errata through GitHub. In addition, readers like Graziano Misuraca, who looked through the book closely, providing valuable feedback.
Some copy, particularly in cheatsheets, comes straight out of the manual of tmux, which is ISC-licensed.
Book Updates and tmux changes
This book was written for tmux 2.3, released September 2016.
As of January 2017, itรขยยs trivial to push out minor changes to Leanpub. Kindle is harder.
tmux does intermittently receive updates. Iรขยยve accommodated many over the past 5 years on my personal configurations and software libraries set with continuous integration tests against multiple tmux versions. Sometimes, publishers overplay version numbers to make it seem as if itรขยยs worth striking a new edition of a book over it. Itรขยยs effective for them, but Iรขยยd rather be honest to my readership.
continuous integration tests against multiple tmux versions
If youรขยยre considering keeping up to date with new features and adjustments to tmux, the CHANGES file in the project source serves as a way to see whatรขยยs updated between official releases.
1. Thinking in tmux
--------------------------------------------------------------------------------
In the world of modern computing, user interaction has 2 realms:
1. The text realm
2. The graphical realm
tmux lives in the text realm in which fixed-width fonts appear in a rectangular grid in a window, like in a terminal from the 1980s.
Window manager for the terminal
tmux is to the console what a desktop is to GUI apps. Itรขยยs a world inside the text dimension. Inside tmux, you can:
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ tmux โ รขยยDesktopรขยย-Spea โ Plain English โ โ โ k โ โ โโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ Multiplexer โ Multi-tasking โ Multiple applications โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ ร โ simultaneously. โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Session โ Desktop โ Applications are visible here โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Window โ Virtual Desktop or โ Desktop containing its own screen โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ applications โ ร โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Pane โ Application โ Performs operations โ โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Just like in a graphical desktop environment, they throw in a clock, too.
top-left: KDE. top-right: Windows 10. center: macOS Sierra. bottom: tmux 2.3 default status bar.
Multitasking
tmux allows you to keep multiple terminals running on the same screen. After all, the abbreviation รขยยtmuxรขยย comes from - Terminal Multiplexer.
In addition to multiple terminals on one screen, tmux allows you to create and link multiple รขยยwindowsรขยย within the confines of the tmux session you attached.
Even better, you can copy and paste and scroll. No requirement for graphics either, so you have full power, even if youรขยยre SSHรขยยing or on a system without a display server such as X.
Here are a few common scenarios:
pane to get a live stream of the latest system events.
gulp-watch, grunt-watch, guard, or entr. On file change, you could do stuff like: + rebuild LESS or SASS files, minimize CSS and/or assets and static files + lint with linters, like cpplint, Cppcheck, rubocop, ESLint, or Flake8 + rebuild with make or ninja + reload your Express server + run any other custom command of your liking
while leaving two others open for CLI commands and building via make or ninja.
vim + building a C++ project w/ CMake + Ninja using entr to rebuild on file changes, LLDB bottom right
With tmux, you quickly have the makings of an IDE! And on your terms.
Keep your applications running in the background
Sometimes, GUI applications will have an option to be sidelined to the system tray to run in the background. The application is out of sight, but events and notifications can still come in, and the app can be instantly brought to the foreground.
In tmux, a similar concept exists, where we can รขยยdetachรขยย a tmux session.
Detaching can be especially useful on:
a tmux session, you restart X. Instead of losing your processes as you normally would if you were using an X terminal, like xterm or konsole, youรขยยd be able to tmux attach after and find all the processes inside that were alive and kicking all along.
can detach your tmux workspace at work before you clock out, then the next morning, reattach your session. Ahhh. Refreshing. :)
months later, and as a reflex, tmux attach to see if there is anything on there. And boom, youรขยยre back in a session youรขยยve forgotten about, but still jogs your memory to what you were tweaking or fixing. Itรขยยs like a hack to restore your memory.
Powerful combos
Chatting on irssi or weechat, one of the รขยยclassic combosรขยย, along with a bitlbee server to manage AIM, MSN, Google Talk, Jabber, ICQ, even Twitter. Then, you can detach your IRC and รขยยidleรขยย in your favorite channels, stay online on instant messengers, and get back to your messages when you return.
Chatting on weechat w/ tmux ๐ท
Chatting on weechat w/ tmux
Some keep development services running in a session. Hearty emphasis on development, you probably will want to daemonize and wrap your production web applications, using a tool like supervisor, with its own safe environmental settings.
You can also have multiple users attach their clients to the same sessions, which is great for pair programming. If you were in the same session, you and the other person would see the same thing, share the same input, and the same active window and pane.
The above are just examples; any general workspace youรขยยd normally use in a terminal could work, especially projects or repetitive efforts you multitask on. The tips and tricks section will dive into specific flows you can use today.
Do tmux sessions persist after a system restart?
Unfortunately, no. A restart will kill the tmux server and any processes running within it.
Thankfully, the modern server can stay online for a long time. Even for consumer laptops and PCรขยยs with a day or two uptime, having tmux persist tasks for organizational purposes is satisfactory to run it.
It comes as a disappointment, because some are interested in being able to persist a tree of processes after restart. It goes out of the scope of what tmux is meant to do.
For tasks you repeat often, you can always use a tool, like tmuxp, tmuxinator, or teamocil, to resume common sessions.
Besides session managers, tmux-resurrect attempts to preserve running programs, working directories, and so on within tmux. The benefit with tmux-resurrect is thereรขยยs no JSON/YAML config needed.
Summary
tmux is a versatile addition to your terminal toolbelt. It helps you cover the gaps between multitasking and workspace organization youรขยยd otherwise lose, since thereรขยยs no GUI. In addition, it includes a nice ability to detach workspaces to the background and reattach later.
In the next chapter, we will touch on some terminal basics before diving deeper into tmux.
2. Terminal fundamentals
--------------------------------------------------------------------------------
Before getting into tmux, a few fundamentals of the command line should be reviewed. Often, weรขยยre so used to using these out of street smarts and muscle memory, a great deal of us never see the relation of where these tools stand next to each other.
Seasoned developers are familiar with Zsh, Bash, iTerm2, konsole, /dev/tty, shell scripting, and so on. If you use tmux, youรขยยll be around these all the time, regardless whether youรขยยre in a GUI on a local machine or SSHรขยยing into a remote server.
If you want to learn more about how processes and TTYs work at the kernel level (data structures and all), the book The Design and Implementation of the FreeBSD Operating System (2nd Edition) by Marshall Kirk McKusick is nice, particularly, Chapter 4, Process Management and Section 8.6, Terminal Handling. The TTY demystified by Linus ร
kesson (available online) dives into the TTY and is a good read.
The Design and Implementation of the FreeBSD
Operating System (2nd Edition)
Much more exists to glean off the history of Unix, 4.2 BSD, etc. I probably could have a coffee / tea with you discussing it for hours. You could look at it from multiple perspectives (The C Language, anything from the Unix/BSD lineage, etc.), and some clever fellow would likely chime in, mentioning Linux, GNU, and so on. Itรขยยs like Game of Thrones; thereรขยยs multiple story arcs you can follow, some of which intersect. A few good video resources would be A Narrative History of BSD by Marshall Kirk McKusick, The UNIX Operating System by AT&T, Early days of Unix and design of sh by Stephen R. Bourne.
Early days of Unix and design of sh
POSIX standards
Operating systems like macOS (formerly OS X), Linux, and the BSDs, follow something similar to the POSIX specification in terms of how they square away various responsibilities and interfaces of the operating system. Theyรขยยre categorized as รขยยMostly POSIX-compliantรขยย.
รขยยMostly POSIX-compliantรขยย
In daily life, we often break compatibility with POSIX standards for reasons of sheer practicality. Operating systems, like macOS, will drop you right into Bash. make(1), a POSIX standard, is GNU Make on macOS by default. Did you know, as of September 2016, POSIX Make has no conditionals?
Iรขยยm not saying this to take a run at purists. As someone who tries to remain compatible in my scripting, it gets hard to do simple things after a while. On FreeBSD, the default Make (PMake) uses dots between conditionals:
But on most Linux systems and macOS, GNU Make is the default, so they get to do:
This is one of the many tiny inconsistencies that span operating systems, their userlands, their binary / library / include paths, and adherence / interpretation of the Filesystem Hierarchy Standard or whether they follow their own.
Find your path
Most operating systems inspired by Unix (BSDรขยยs, macOS, Linux) will allow you to get the info of your systemsรขยย filesystem hierarchy via hier(7).
These differences add up. A good deal of software infrastructure out there exists solely to abstract the differences across them. For example: CMake, Autotools, SFML, SDL2, interpreted programming languages, and their standard libraries are dedicated to normalizing the banal differences across BSD-derivatives and Linux distributions. Many, many #ifdef preprocessor directives in your C and C++ applications. You want open source, you get choice, but be aware; thereรขยยs a lot of upkeep cost in keeping these upstream projects (and even your personal ones) compatible. But I digress, back to terminal stuff.
Why does it matter? Why bring it up? Youรขยยll see this stuff everywhere. So, letรขยยs separate the usual suspects into their respective categories.
Terminal interface
The terminal interface can be best introduced by citing official specification, laying out its technical properties, interfaces, and responsibilities. This can be viewed in its POSIX specification.
This includes TTYs, including text terminals and X sessions within them. On Linux / BSD systems, you can switch between sessions via <ctrl-alt-F1> through <ctrl-alt-F12>.
Terminal emulators
GUI Terminals: Terminal.app, iterm, iterm2, konsole, lxterm, xfce4-terminal, rxvt-unicode, xterm, roxterm, gnome terminal, cmd.exe + bash.exe
Shell languages
Shell languages are programming languages. You may not compile the code into binaries with gcc or clang, or have shiny npm package manager for them, but a language is a language.
Each shell interpreter has its own language features. Like with shells, many will resemble the POSIX shell language and strive to be compatible with it. Zsh and Bash should be able to understand POSIX shell scripts you write, but not the other way around (we will cover this in shell interpreters).
The first line of shell file is the shebang statement, which points to the interpreter to run the script in. They normally use the .sh extension, but they can also be .zsh, .csh and so on if theyรขยยre for a specific interpreter.
Zsh scripts are implemented by the Zsh shell interpreter, Bash scripts by Bash. But the languages are not as closely regulated and standardized as, say, C++รขยยs standards committee workgroups or pythonรขยยs PEPs. Bash and Zsh take features from Korn and C Shellรขยยs languages, but without all the ceremony and bureaucracy other languages espouse.
standards committee
Shell interpreters (Shells)
Examples: POSIX sh, Bash, Zsh, csh, tcsh, ksh, fish
Shell interpreters implement the shell language. They are a layer on top of the kernel and are what allow you, interactively, to run commands and applications inside them.
As of October 2016, the latest POSIX specification covers in technical detail the responsibilities of the shell.
For shells and operating systems: each distro or group does their own darn thing. On most Linux distributions and macOS, youรขยยll typically be dropped into Bash.
On FreeBSD, you may default to a plain vanilla sh unless you specify otherwise during the installation process. In Ubuntu, /bin/sh used to be bash (Bourne Again Shell) but was replaced with dash (Debian Almquist Shell). So, here, you are thinking รขยยhmm, /bin/sh, probably just a plain old POSIX shellรขยย; however, system startup scripts on Ubuntu used to allow non-POSIX scripting via Bash. This is because specialty shell languages, such as Bash and Zsh, add helpful and practical features, but theyรขยยre not portable. For instance, you would need to install the Zsh interpreter across all your systems if you rely on Zsh-specialized scripting. If you conformed with POSIX shell scripting, your scripting would have the highest level of compatibility at the cost of being more verbose.
Recent versions of macOS include Zsh by default. Linux distributions typically require you to install it via package manager and install it to /usr/bin/zsh. BSD systems build it via the port system, pkg(8) on FreeBSD, or pkg_add(1) on OpenBSD, and it will install to /usr/local/bin/zsh.
Itรขยยs fun to experiment with different shells. On many systems, you can use chsh -s to update the default shell for a user.
The other thing to mention is, for chsh -s to work, you typically need to have it added to /etc/shells.
Summary
To wrap it up, you will hear people talking about shells all the time. Context is key. It could be:
shell and see what happens.รขยย (Press q to quit.)
popular for small hosts to sell รขยยC Shellsรขยย with root access.
related to the scriptsรขยย behavior, or something about the shell language.
But overall, after this overview, go back to doing what youรขยยre doing. If shell is what people say and they understand it, use it. The backing you have here should make you more confident in yourself. These days, itรขยยs an ongoing battle catching our street smarts up with book smarts.
In the next chapter, we will touch some terminal basics before diving deeper into tmux.
3. Practical usage
--------------------------------------------------------------------------------
This is the easiest part; open your terminal and type tmux, hit enter.
Youรขยยre in tmux.
The prefix key
The prefix is how we send commands into tmux. With this, we can split windows, move windows, switch windows, switch sessions, send in custom commands, you name it.
And itรขยยs a hump we have to get over.
Itรขยยs kind of like Street Fighter. In this video game, the player inputs a combination of buttons in sequence to perform flying spinning kicks and shoot fireballs; sweet. As the player grows more accustomed with the combos, they repeat moves by intuition, since they develop muscle memory.
Without understanding how to send command sequences to tmux via the prefix key, youรขยยll be dead in the water.
Key sequences will come up later if you use Vim, Emacs, or other TUI (Terminal User Interface) applications. If you havenรขยยt internalized the concept, letรขยยs do it now. Prior experience command sequences in TUI/GUI applications will come in handy.
When you memorize a key combo, itรขยยs one less time youรขยยll be moving your hand away from the keyboard to grab your mouse. You can focus your short-term memory on getting stuff done, resulting in fewer mistakes.
Coming from GNU Screen?
Your tmux prefix key can be set via your tmux configuration later! In your ~/.tmux.conf file, set the prefix option:
This will set the prefix key to screen(1)รขยยs (another terminal multiplexerรขยยs) prefix key.
The default leader prefix is <Ctrl-b>. While holding down the control key, press b.
Sending tmux commands
Practice:
1. Press control key down and hold it.
2. Press b and hold it.
3. Release both keys at the same time.
Try it a few times. It may feel unnatural until youรขยยve done it a couple times, which is normal when memorizing shortcuts.
Now, letรขยยs try something:
<Ctrl-b> d. So,
1. Press control key down and hold it.
2. Press b and hold it.
3. Release both keys at the same time.
4. Hit d!
Youรขยยve sent tmux your first command, and youรขยยre now outside of tmux!
Youรขยยve detached the tmux session you were in. You can reattach via $ tmux attach.
Nested tmux sessions
You can also send the prefix key to nested tmux sessions. For instance, if youรขยยre inside a tmux client on a local machine and you SSH into a remote machine in one of your panes, on the remote machine, you can attach the client via tmux attach as you normally would. To send the prefix key to the machineรขยยs tmux client, not your local one, hit the prefix key again.
So, if your prefix key is the default, <Ctrl-b>, do <Ctrl-b> + b again, then hit the shortcut for what you want to do.
Example: If you wanted to create a window on the remote machine, which would normally be <Ctrl-b> + c locally, itรขยยd be <Ctrl-b> + b + c.
Hereinafter, the book will refer to shortcuts by Prefix. Instead of <Ctrl-b> + d, you will see Prefix + d.
Session persistence and the server model
If you use Linux or a similar system, youรขยยve likely brushed through Job Control, such as fg(1), jobs(1). tmux behavior feels similar, like you ran <Ctrl-z> except, technically, you were in a รขยยjobรขยย all along. You were just using a client to view it.
Another way of understanding it: <Ctrl-b> + d closed the client connection, therefore, รขยยdetachedรขยย from the session.
Your tmux client disconnected from the server instance. The session, however, is still running in the background.
Itรขยยs all commands
Multiple roads can lead you to the same behavior. Commands are what tmux uses to define instructions for setting options, resizing, renaming, traversing, switching modes, copying and pasting, and so forth.
$ tmux command.
execute commands via keybindings via bind-key.
cmd-.
Summary
Weรขยยve established tmux automatically creates a server upon starting it. The server allows you to detach and later reattach your work. The keyboard sequences you send to tmux require understanding how to send the prefix key.
Keyboard sequences, configuration, and command line actions all boil down to the same core commands inside tmux. In our next chapter, we will cover the server.
4. Server
--------------------------------------------------------------------------------
The server holds sessions and the windows and panes within them.
When tmux starts, you are connected to a server via a socket connection. What you see presented in your shell is merely a client connection. In this chapter, we uncover the invisible engine enabling your terminal applications to persist for months or even years at a time.
What? tmux is a server?
Often, when รขยยserverรขยย is mentioned, what comes to mind for many may be rackmounted hardware; to others, it may be software running daemonized on a server and managed through a utility, like upstart, supervisor, and so on.
Unlike web or database software, tmux doesnรขยยt require specialized configuration settings or creating a service entry to start things.
tmux uses a client-server model, but the server is forked to the background for you.
Zero config needed
You donรขยยt notice it, but when you use tmux normally, a server is launched and being connected via a client.
tmux is so streamlined, the book could continue to explain usage and not even mention servers. But, Iรขยยd rather you have a true understanding of how it works on systems. The implementation feels like magic, while living up to the unix expectations of utilitarianism. One cannot deny itรขยยs exquisitely executed from a user experience standpoint.
How is it utilitarian? Weรขยยll go into it more in future chapters, where we dive into Formats, Targets, and tools, such as libtmux I made, which utilize these features.
It surprises some, because servers often beget a setup process. But servers being involved doesnรขยยt entail hours of configuration on each machine you run on. Thereรขยยs no setup.
When people think server, they think pain. It invokes an image of digging around /etc/ for configuration files and flipping settings on and off just to get basic systems online. But not with tmux. Itรขยยs a server, but in the good way.
Stayinรขยย alive
The server part of tmux is how your sessions can stay alive, even after your client is detached.
You can detach a tmux session from an SSH server and reconnect later. You can detach a tmux session, stop your X server in Linux/BSD, and reattach your tmux session in a TTY or new X server.
The tmux server wonรขยยt go away until all sessions are closed.
Servers hold sessions
One server can contain one or multiple sessions.
Starting tmux after a server already is running will create a new session inside the existing server.
Advanced: Multiple servers
tmux is nimble. To use a separate server, pass in the -L flag to any command.
tmux -L moo - connect to server under socket name รขยยmooรขยย and attach a new session. Create server if none already exists for socket.
tmux -L moo attach will attempt to re-attach a session if one exists.
How servers are รขยยnamedรขยย
The default name for the server is default, which is stored as a socket in /tmp. The default directory for storing this can be overridden via setting the TMUX_TMPDIR environment variable.
So, something like:
$ export TMUX_TMPDIR=$HOME $ tmux
Will give you a tmux directory created within your $HOME folder. On OS X, your home folder will probably be something like /Users/yourusername. On other systems, it may be /home/yourusername. If you want to find out, type $ echo $HOME.
Clients
Servers will have clients (you) connecting to them.
When you connect to a session and see windows and panes, itรขยยs a client connection into tmux.
You can retrieve a list of active client connections via:
These commands and the other list- commands, in practice, are rare. But, they are part of tmux scriptability should you want to get creative. The scripting tmux chapter will cover this in greater detail.
Clipboard
tmux clients wield a powerful clipboard feature to copy and paste across sessions, windows, and panes.
Much like vi, tmux handles copying as a mode in which a pane is temporarily placed. When inside this mode, text can be selected and copied to the paste buffer, tmuxรขยยs clipboard.
The default key to enter copy mode is Prefix + [.
1. From within, use [space] to enter copy mode.
2. Use the arrow keys to adjust the text to be selected.
3. Press [enter] to copy the selected text.
The default key to paste the text copied is Prefix + ].
Vi-like copy-paste
In your config, put this:
# Vi copypaste mode set-window-option -g mode-keys vi bind-key -t vi-copy 'v' begin-selection bind-key -t vi-copy 'y' copy-selection # starting with tmux version 2.6 this changes to: bind-key -Tcopy-mode-vi 'C-v' send -X begin-selection bind-key -Tcopy-mode-vi 'C-y' send -X copy-selection
In addition to the รขยยcopy modeรขยย, tmux has advanced functionality to programmatically copy and paste. Later in the book, the Capturing pane content section in the Scripting tmux chapter goes into $ tmux capture-pane and how you can use targets to copy pane content into your paste buffer or files with $ tmux save-buffer.
Summary
The server is one of the fundamental underpinnings of tmux. Initialized automatically to the user, it persists by forking into the background. Running behind the scenes, it ensures sessions, windows, panes, and buffers are operating, even when the client is detached.
The server can hold one or more sessions. You can copy and paste between sessions via the clipboard. In the next chapter, we will go deeper into the role sessions play and how they help you organize and control your terminal workspace.
5. Sessions
--------------------------------------------------------------------------------
Welcome to the session, the highest-level entity residing in the server instance. Server instances are forked to the background upon starting a fresh instance and reconnected to when reattaching sessions. Your interaction with tmux will have at least one session running.
A session holds one or more windows.
The active window will have a * symbol next to it.
The first window, ID 1, titled "manuscript" is active. The second window, ID 2, titled zsh. ๐ท
The first window, ID 1, titled รขยยmanuscriptรขยย is active. The second window, ID 2, titled zsh.
Creating a session
The simplest command to create a new session is typing tmux:
The $ tmux application, with no commands is equivalent to $ tmux new-session. Nifty!
By default, your session name will be given a number, which isnรขยยt too descriptive. What would be better is:
$ tmux new-session -s'my rails project'
Switching sessions within tmux
Some acquire the habit of detaching their tmux client and reattaching via tmux att -t session_name. Thankfully, you can switch sessions from within tmux!
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ Prefix + ( โ Switch the attached client to the previous session. โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Prefix + ) โ Switch the attached client to the next session. โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Prefix + L โ Switch the attached client back to the last โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ session. โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Prefix + s โ Select a new session for the attached client โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ interactively. โ โโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Prefix + s will allow you to switch between sessions within the same tmux client.
This command name can be confusing. switch-client will allow you to traverse between sessions in the server.
Example usage:
$ tmux switch-client -t dev
If already inside a client, this will switch to a session, named รขยยdevรขยย, if it exists.
Naming sessions
Sometimes, the default session name given by tmux isnรขยยt descriptive enough. It only takes a few seconds to update it.
You can name it whatever you want. Typically, if Iรขยยm working on multiple web projects in one session, Iรขยยll name it รขยยwebรขยย. If Iรขยยm assigning one software project to a single session, Iรขยยll name it after the software project. Youรขยยll likely develop your own naming conventions, but anything is more descriptive than the default.
Renaming a session '0' to 'react web' ๐ท
Renaming a session รขยย0รขยย to รขยยreact webรขยย
If you donรขยยt name your sessions, itรขยยll be difficult to keep track of what the session contains. Sometimes, you may forget you have a project opened, especially if your machine has been running for a few days, weeks, or months. You can save time by reattaching your session and avoid creating a duplicate.
You can rename sessions from within tmux with Prefix + $. The status bar will be temporarily altered into a text field to allow altering the session name.
Through command line, you can try:
$ tmux rename-session -t 1 "my session"
Does my session exist?
If youรขยยre scripting tmux, you will want to see if a session exists. has-session will return a 0 exit code if the session exists, but will report a 1 exit code and print an error if a session does not exist.
It assumes the session รขยย1รขยย exists; itรขยยll just return 0 with no output.
But if it doesnรขยยt, youรขยยll get something like this in a response:
$ tmux has-session -t 1 > can't find session 1
To try it in a shell script:
if tmux has-session -t 0 ; then echo "has session 0" fi
Summary
In this chapter, you learned how to rename sessions for organizational purposes and how to switch between them quickly.
Youรขยยll always be attached to a session when youรขยยre using a client in tmux. When the last remaining session is closed, the server will close also.
Think of sessions as workspaces designed to help organize a set of windows, analogous to virtual desktop spaces in GUI computing.
In the next chapter, we will go into windows, which, like sessions, are also nameable and let you switch between them.
6. Windows
--------------------------------------------------------------------------------
Windows hold panes. They reside within a session.
They also have layouts, which can be one of many preset dimensions or a custom one done through pane resizing.
You can see the current windows through the status bar at the bottom of tmux.
Creating windows
All sessions start with at least one window open. From there, you can create and kill windows as you see fit.
Window indexes are numbers tmux uses to determine ordering. The first windowรขยยs index is 0, unless you set it via base-index in your configuration. I usually set -g base-index 1 in my tmux configuration, since 0 is after 9 on the keyboard.
Prefix + c will create a new window at the first open index. So, if youรขยยre in the first window, and there is no second window created, it will create the second window. If the second window is already taken, and the third hasnรขยยt been created, it will create the third window.
If the base_index is 1 and there are 7 windows created, with the 5th window missing, creating a new window will fill the empty 5th index, since itรขยยs the next one in order and nothing is filling it. The next created window would be the eighth.
Naming windows
Just like with sessions, windows can have names. Labelling them helps keep track of what youรขยยre doing inside them.
Renaming a window 'zsh' to 'renamed' ๐ท
Renaming a window รขยยzshรขยย to รขยยrenamedรขยย
When inside tmux, the shortcut Prefix + , is most commonly used. It opens a prompt in the tmux status line, where you can alter the name of the current window.
The default numbers given to windows also become muscle memory after a while. But naming helps you when youรขยยre in a new tmux flow and want to organize yourself. Also, if youรขยยre sharing tmux with another user, itรขยยs good practice to give a hint whatรขยยs inside the windows.
Traversing windows
Moving around windows is done in two ways, first, by iterating through via Prefix + p and Prefix + n and via the window index, which takes you directly to a specific window.
Prefix + 1, Prefix + 2, and so onรขยยฆ allows quickly navigating to windows via their index. Unlike window names, which change, indexes are consistent and only require a quick key combo for you to invoke.
Prompt for a window index (useful for indexes greater than 9) with Prefix + '. If the window index is 10 or above, this will help you a lot.
Bring up the last selected window with Prefix + l.
A list of current windows can be displayed with Prefix + w. This also gives some info on whatรขยยs inside the window. Helpful when juggling a lot of things!
Moving windows
Windows can also be reordered one by one via move-window and its associated shortcut. This is helpful if a window is worth keeping open but not important or rarely looked at. After you move a window, you can continue to reorder them at any point in time after.
The command $ tmux move-window can be used to move windows.
The accepted arguments are -s (the window you are moving) and -t, where you are moving the window to.
You can also use $ tmux movew for short.
Example: move the current window to number 2:
Example: move window 2 to window 1:
The shortcut to prompt for an index to move the current window to is Prefix + ..
Layouts
Prefix + space switches window layouts. These are preset configurations automatically adjusting proportions of panes.
As of tmux 2.3, the supported layouts are:
Specific touch-ups can be done via resizing panes.
To reset the proportions of the layout (such as after splitting or resizing panes), you have to run $ tmux select-layout again for the layout.
This is different behavior than some tiling window managers. awesome and xmonad, for instance, automatically handle proportions upon new items being added to their layouts.
To allow easy resetting to a sensible layout across machines and terminal dimensions, you can try this in your config:
bind m set-window-option main-pane-height 60\; select-layout main-horizontal
This allows you to set a main-horizontal layout and automatically set the bottom panes proportionally on the bottom every time you do Prefix + m.
Layouts can also be custom. To get the custom layout snippet for your current window, try this:
# awk(1) $ tmux lsw -F "#{window_active} #{window_layout}" | awk '$1{print $2}' # grep(1) + cut(1) $ tmux lsw -F "#{window_active} #{window_layout}" | grep "^1" | cut -d " " -f2
To apply this layout:
$ tmux lsw -F "#{window_active} #{window_layout}" | awk '$1{print $2}' > 5aed,176x79,0,0[176x59,0,0,0,176x19,0,60{87x19,0,60,1,88x19,88,60,2}] # Alternant to above: $ tmux lsw -F "#{window_active} #{window_layout}" | grep "^1" | cut -d " " -f2 # resize your panes or try doing this in another window to see the outcome $ tmux select-layout "5aed,176x79,0,0[176x59,0,0,0,176x19,0,60{87x19,0,60,1,88x\ 19,88,60,2}]"
Closing windows
There are two ways to kill a window. First, exit or kill every pane in the window. Panes can be killed via Prefix + x or by Ctrl + d within the paneรขยยs shell. The second way, Prefix + &, prompts if you really want to delete the window. Warning: this will destroy all the windowรขยยs panes, along with the processes within them.
From inside the current window, try this:
Another thing, when scripting or trying to kill the window from outside, use a target of the window index:
If youรขยยre trying to find the target of the window to kill, they reside in the number in the middle section of the status line and via $ tmux choose-window. You can hit รขยยreturnรขยย after youรขยยre in choose-window to go back to where you were previously.
Summary
In this chapter, you learned how to manipulate windows via renaming and changing their layouts, a couple of ways to kill windows in a pinch or in when shell scripting tmux. In addition, this chapter demonstrated how to save any tmux layout by printing the window_layout template variable.
If you are in a tmux session, youรขยยll always have at least one window open, and youรขยยll be in it. And within the window will be รขยยpaneรขยย; a shell within a shell. When a window closes all of its panes, the window closes too. In the next chapter, weรขยยll go deeper into panes.
7. Panes
--------------------------------------------------------------------------------
Panes are pseudoterminals encapsulating shells (e.g., Bash, Zsh). They reside within a window. A terminal within a terminal, they can run shell commands, scripts, and programs, like vim, emacs, top, htop, irssi, weechat, and so on within them.
Creating new panes
To create a new pane, you can split-window from within the current window and pane you are in.
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ Prefix + % โ split-window -h (split horizontally) โ โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Prefix + " โ split-window -v (split vertically) โ โโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
You can continue to create panes until youรขยยve reached the limit of what the terminal can fit. This depends on the dimensions of your terminal. A normal window will usually have 1 to 5 panes open.
Example usage:
# Create pane horizontally, $HOME directory, 50% width of current pane $ tmux split-window -h -c $HOME -p 50 vim
# create new pane, split vertically with 75% height tmux split-window -p 75
Traversing Panes
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ Prefix + ; โ Move to the previously active pane. โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Prefix + Up / โ Change to the pane above, below, โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Down / Left / โ to the left, or to the โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Right โ the right of the current pane. โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Prefix + o โ Select the next pane in the current window. โ โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Moving around vimtuitively
If you like vim (hjkl) keybindings, add these to your config:
# hjkl pane traversal bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R
Zoom in
To zoom in on a pane, navigate to it and do Prefix + z.
You can unzoom by pressing Prefix + z again.
In addition, you can unzoom and move to an adjacent pane at the same time using a pane traversal key.
Behind the scenes, the keybinding is a shortcut for $ tmux resize-pane -Z. So, if you ever wanted to script tmux to zoom/unzoom a pane or apply this functionality to a custom key binding, you can do that too, for instance:
bind-key -T prefix y resize-pane -Z
This would have Prefix + y zoom and unzoom panes.
Resizing panes
Pane size can be adjusted within windows via window layouts and resize-pane. Adjusting window layout switches the proportions and order of the panes. Resizing the panes targets a specific pane inside the window containing it, also shrinking or growing the size of the other columns or rows. Itรขยยs like adjusting your car seat or reclining on a flight; if you take up more space, something else will have less space.
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโก โ Prefix M-Up โ resize-pane -U 5 โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix M-Down โ resize-pane -D 5 โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix M-Left โ resize-pane -L 5 โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix M-Right โ resize-pane -R 5 โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix C-Up โ resize-pane -U โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix C-Down โ resize-pane -D โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix C-Left โ resize-pane -L โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค โ Prefix C-Right โ resize-pane -R โ โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ
Outputting pane to a file
You can output the display of a pane to a file.
$ tmux pipe-pane -o 'cat >>~/output.#I-#P'
The #I and #P are formats for window index and pane index, so the file created is unique. Clever!
Summary
Panes are shells within a shell. You can keep adding panes to a tmux window until you run out of room on your screen. Within your shell, you can tail -F log files, write and run scripts, and run curses-powered applications, like vim, top, htop, ncmpcpp, irssi, weechat, mutt, and so on.
You will always have at least one pane open. Once you kill the last pane in the window, the window will close. Panes are also resizable; you can resize panes by targeting them specifically and changing the window layout.
In the next chapter, we will go into the ways you can customize your tmux shortcuts, status line, and behavior.
8. Configuration
--------------------------------------------------------------------------------
Most tmux users break away from the defaults by creating their own customized configurations. These configurations vary from the trivial, such as adding keybindings, and adjusting the prefix key, to complex things, such as decking out the status bar with system stats and fancy glyphs via powerlines.
Configuration of tmux is managed through .tmux.conf in your $HOME directory. The paths ~/.tmux.conf and $HOME/.tmux.conf should work on OS X, Linux, and BSD.
Configuration is applied upon initially starting tmux. The contents of the configuration are tmux commands. The file can be reloaded later via source-file, which is discussed in this chapter.
For a sample config, I maintain a pretty decked out one at https://github.com/tony/tmux-config. Itรขยยs permissively licensed, and youรขยยre free to copy and paste from it as you wish.
https://github.com/tony/tmux-config
Custom Configs
You can specify your config via the -f command. Like this:
$ tmux -f path/to/config.conf
Note: If a tmux server is running in the background and you want to test a fresh config, you must either shut down the rest of the tmux sessions or use a different socket name. Like this:
$ tmux -f path/to/config.conf -Ltesting_tmux
And you can treat everything like normal; just keep passing -Ltesting_tmux (or whatever socket name you feel like testing configs with) for reuse.
$ tmux -Ltesting_tmux attach
Reloading configuration
You can apply config files in live tmux sessions. Compare this to source or รขยยdotรขยย in the POSIX standard.
Prefix + : will open the tmux prompt, then type:
:source /path/to/config.conf
And hit return.
$ tmux source-file /path/to/config.conf can also achieve the same result via command line.
Easy reloadinรขยย
Even better, often, you will keep your default tmux config stored in $HOME/.tmux.conf. So, what can you do? You can bind-key to source-file ~/.tmux.conf:
bind r source ~/.tmux.conf
You can also have it give you a confirmation afterwards:
bind r source ~/.tmux.conf\; display "~/.tmux.conf sourced!"
Now, you can type Prefix + r to get the config to reload.
Note that reloading the configuration only re-runs the configuration file. It will not reset keybindings or styling you apply to tmux.
How configs work
The tmux configuration is processed just like run commands in a ~/.zshrc or ~/.bashrc file. bind r source ~/.tmux.conf in the tmux configuration is the same as $ tmux bind r source ~/.tmux.conf.
You could always create a shell script prefixing tmux in front of commands and run it on fresh servers. The result is the same. Same goes if you manually type in $ tmux set-option and $ tmux bind-key commands into any terminal (in or outside tmux).
This in .tmux.conf:
Is the same as having no .tmux.conf (or $ tmux -f/dev/null) and typing:
$ tmux bind-key a send-prefix
in a newly started tmux server.
The important thing to internalize is that a tmux configuration consists of setting server options (set-option -s), global session (set-option -g), and window options (set-window-option -g).
The rest of this chapter is going to proceed cookbook-style. You can pick out these tweaks and add them to your .tmux.conf and reload.
Server options
Server options are set with set-option -s option value.
Tweak timing between key sequences
Terminal coloring
If youรขยยre having an issue with color detail in tmux, it may help to set default-terminal to screen-256color.
set -g default-terminal "screen-256color"
This sets the TERM variable in new panes.
Session options
Aside from the status bar, covered in the next chapter, most user configuration will be custom keybindings. This section covers the few generic options, and the next section goes into snippets involving keybindings.
Base index
This was mentioned earlier in the book, but itรขยยs a favorite tweak of many tmux users, who find it more intuitive to start their window counting at 1, rather than the default, 0. To set the starting number (base index) for windows:
Setting base-index assures newly created windows start at 1 and count upwards.
Window options
Window options are set via set-option -w or set-window-option. They are the same thing.
Automatic window naming
Setting automatic-rename alters the name of the window based upon its active pane:
set-window-option -g automatic-rename
Automatic renaming will be disabled for the window if you rename it manually.
Keybindings
Prefix key
The default prefix key in tmux is <Ctrl-b>. You can customize it by setting a new prefix and unsetting the default. To set the prefix to <Ctrl-a>, like GNU Screen, try this:
set-option -g prefix C-a unbind-key C-b bind-key a send-prefix
New window with prompt
Prompt for window name upon creating a new window, Prefix + C (capital C):
bind-key C command-prompt -p "Name of new window: " "new-window -n '%%'"
Vi copy-paste keys
This is comprised of two-parts: Setting the mode-keys window option to vi and setting the vi-copy bindings to use v to begin selection and y to yank.
# Vi copypaste mode set-window-option -g mode-keys vi bind-key -t vi-copy 'v' begin-selection bind-key -t vi-copy 'y' copy-selection
hjkl / vi-like pane traversal
Another one for vi fans, this keeps your right hand on the home row when moving directionally across panes in a window.
bind h select-pane -L bind j select-pane -D bind k select-pane -U bind l select-pane -R
Further inspiration
For more ideas, I have a .tmux.conf you can copy-paste from on the internet at https://github.com/tony/tmux-config/blob/master/.tmux.conf.
https://github.com/tony/tmux-config/blob/master/.tmux.conf
In the next chapter, we will go into configuring the status line.
9. Status bar and styling
--------------------------------------------------------------------------------
The status bar, or status line, serves as a customizable taskbar in the bottom of tmux. It is comprised of 3 sections. The status fields on either side of the status line are customizable. The center field is a list of windows.
The status-left and status-right option can be configured with variables.
Itรขยยs configurable through the .tmux.conf file and modifiable live through using $ tmux set-option.
Window status symbols
This window list is between the left and right status bar regions.
tmux indicates status of a window through symbols. See below:
โโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Symbol โ Meaning โ โโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ * โ Denotes the current window. โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ - โ Marks the last window (previously selected). โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ # โ Window is monitored and activity has been detected. โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ! โ A bell has occurred in the window. โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ~ โ The window has been silent for the monitor-silence interval. โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ M โ The window contains the marked pane. โ โโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Z โ The windowรขยยs active pane is zoomed. โ โโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Reminder: A pane can be zoomed via Prefix + z. To unzoom, press Prefix + z or move left / right / up / down panes.
Date and time
status-left and status-right accept variables for the date.
This happens via piping the status templates through format_expand_time in format.c, which routes right into strftime(3) from time.h.
A full list of variables can be found in the documentation for strftime(3). This can be viewed through $ man strftime on Unix-like systems.
Shell command output
You can also call applications, such as tmux-mem-cpu-load, conky, and powerline.
For this example, weรขยยll use tmux-mem-cpu-load. This works on Unix-like systems like FreeBSD, Linux distributions, and macOS.
To build from source, you must have CMake and git, which are available through your package manager. You must have a C++ compiler. On macOS, install Xcode CLI Utilities. You can do this by going to Applications -> Utilities, launching Terminal.app and typing $ xcode-select --install. macOS can use Homebrew to install the CMake and git package. Major Linux distributions package CMake, clang, and git.
Before this step, you can cd into any directory youรขยยre ok keeping code in.
$ git clone https://github.com/thewtex/tmux-mem-cpu-load.git $ cd tmux-mem-cpu-load $ mkdir ./build $ cd ./build $ cmake .. $ make # macOS, no sudo required $ make install # Linux, BSD will require sudo / root to install $ sudo make install
If successful, you should see the output below:
[100%] Built target tmux-mem-cpu-load Install the project... -- Install configuration: "MinSizeRel" -- Installing: /usr/local/bin/tmux-mem-cpu-load
You can remove the source code you cloned from the computer. The compiled application is installed.
You can now add #(tmux-mem-cpu-load) to your status-left or status-right option. In the รขยยDressed upรขยย example below, I use status-left and also theme it to be green:
So to apply it to your theme, you need to double check what you already have. You may have information on there you want to keep.
$ tmux show-option -g status-right status-right " "#{=21:pane_title}" %H:%M %d-%b-%y"
Copy what you had in response (or change, rearrange as you see fit) then add the #(tmux-mem-cpu-load) to it. You can apply the new status line in your current tmux session via $ tmux set-option -g status-right:
$ tmux set-option -g status-right '"#{=21:pane_title}" #(tmux-mem-cpu-load) %H:\ %M %d-%b-%y'
Also, note how I switched out the double quotes on either side of the option with single quotes. This is required, since there are double quotes inside.
You can do this with anything, for instance, try adding uptime. This could be done by adding #(uptime) to your status line. Typically the output is pretty long, so trim it down by doing something like this:
`#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",")``
In the next section, we go into how you can style (color) tmux.
Styling
The colors available to tmux are:
brightblue, brightmagenta, brightcyan.
Status line
You can use [bg=color] and [fg=color] to adjust the text color and background within for status line text. This works on status-left and status-right.
Letรขยยs say you want to style the background:
Command: $ tmux set-option status-style fg=white,bg=black
In config: status-style fg=white,bg=black
In the examples at the end of the chapter, you will see complete examples of how colors can be used.
Clock styling
You can style the color of the tmux clock via:
set-option -g clock-mode-colour white
Reminder: Clock mode can be opened with $ tmux clock-mode or Prefix + t. Pressing any key will exit clock mode.
Prompt colors
The benefit of wrapping your brain around this styling is you will see it message-command-style, message style and so on.
Letรขยยs try this:
$ tmux set-option -ag message-style fg=yellow,blink\; set-option -ag message-st\ yle bg=black
Top: default scheme for prompt. Bottom: newly-styled. ๐ท
Top: default scheme for prompt. Bottom: newly-styled.
Styling while using tmux
So, you want to customize your tmux status line before you write the changes to your config file.
Start by grabbing your current status line section you want to edit, for instance:
$ tmux show-options -g status-left > status-left "[#S] " $ tmux show-options -g status-right > status-right " "#{=21:pane_title}" %H:%M %d-%b-%y"
Also, you can try to snip off the variable with | cut -d' ' -f2-:
$ tmux show-options -g status-left | cut -d' ' -f2- > "[#S] " $ tmux show-options -g status-right | cut -d' ' -f2- > " "#{=21:pane_title}" %H:%M %d-%b-%y"
Then, add the options to your configuration.
To be sure your configuration fully works, you can start it in a different server via tmux -Lrandom, verify the settings, and close it. This is helpful to make sure your config file isnรขยยt missing any styling info.
Toggling status line
The tmux status line can be hidden, as well. Turn it off:
$ tmux set-option status off
And, turn it on:
$ tmux set-option status on
The above is best for scripting, but if youรขยยre binding it to a keyboard shortcut, toggling, or reversing the current option, it can be done via omitting the on/off value:
Bind toggling status line to Prefix + q:
$ tmux bind-key q set-option status
Example: Default config
This is an example of the default config you see if your tmux configuration has no status styling.
status on status-interval 15 status-justify left status-keys vi status-left "[#S] " status-left-length 10 status-left-style default status-position bottom status-right " "#{=21:pane_title}" %H:%M %d-%b-%y" status-right-length 40 status-right-style default status-style fg=black,bg=green
Example: Dressed up
status on status-interval 1 status-justify centre status-keys vi status-left "#[fg=green]#H #[fg=black]รขยยข #[fg=green,bright]#(uname -r | cut -c 1\ -6)#[default]" status-left-length 20 status-left-style default status-position bottom status-right "#[fg=green,bg=default,bright]#(tmux-mem-cpu-load) #[fg=red,dim,bg\ =default]#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") #[fg=white,bg=default]\ %a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d" status-right-length 140 status-right-style default status-style fg=colour136,bg=colour235 # default window title colors set-window-option -g window-status-fg colour244 # base0 set-window-option -g window-status-bg default # active window title colors set-window-option -g window-status-current-fg colour166 # orange set-window-option -g window-status-current-bg default
Configs can print the output of an application. In this example, tmux-mem-cpu-load is providing system statistics in the right-side section of the status line.
To build tmux-mem-cpu-load, you have to install CMake and have a C++ compiler, like clang or GCC.
On Ubuntu, Debian, and Mint machines, you can do this via $ sudo apt-get install cmake build-essential. On macOS w/ brew via $ brew install cmake.
Source: https://github.com/tony/tmux-config
https://github.com/tony/tmux-config
Example: Powerline
The most full-featured solution available for tmux status lines is powerline, which heavily utilizes the shell command outputs, not only to give direct system statistics, but also to generate graphical-like styling.
To get the styling to work correctly, special fonts must be installed. The easiest way to use this is to install powerline fonts, a collection of fixed width coder fonts patched to support Wingdings-like symbols.
Installation instructions are on Read the Docs. For a better idea:
$ pip install --user powerline-status psutil
psutil, a required dependency of powerline, is a cross-platform tool to gather system information.
Assure you properly configured python with your PATHs, and try this:
set -g status-interval 2 set -g status-right '#(powerline tmux right)'
Summary
Configuring the status line is optional. It can use the output of programs installed on your system to give you specialized information, such as CPU, ram, and I/O usage. By default, youรขยยll at least have a window list and a clock.
In addition, you can customize the colors of the status line, clock, and prompt. By default, itรขยยs only a green bar with dark text, so take some time to customize yours, if you want, and save it to your configuration.
In the next chapter, we will go into the command line and scripting features of tmux.
10. Scripting tmux
--------------------------------------------------------------------------------
The command line shortcuts and options in tmux is an area often uncharted.
I will use tables in this chapter. Never get a feeling you have to commit a table to memory immediately. Not my intention, but every personรขยยs way of using tmux is slightly different. I want to cover points most likely to benefit peopleรขยยs flows. Full tables are in the cheatsheets.
Aliases
tmux supports a variety of alias commands. With aliases, instead of typing $ tmux attach-session to attach a session, $ tmux attach could do the trick.
Most aliases come to mind via intuition and are a lot friendlier than typing the full hyphenated commands.
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโ โ Command โ Alias โ โโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโก โ attach-session โ attach โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ break-pane โ breakp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ capture-pane โ capturep โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ display-panes โ displayp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ find-window โ findw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ join-pane โ joinp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ kill-pane โ killp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ kill-window โ killw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ last-pane โ lastp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ last-window โ last โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ link-window โ linkw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ list-panes โ lsp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ list-windows โ lsw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ move-pane โ movep โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ move-window โ movew โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ new-session โ new โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ new-window โ neww โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ next-layout โ nextl โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ next-window โ next โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ pipe-pane โ pipep โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ previous-layout โ prevl โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ previous-window โ prev โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ rename-window โ renamew โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ resize-pane โ resizep โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ respawn-pane โ respawnp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ respawn-window โ respawnw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ rotate-window โ rotatew โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ select-layout โ selectl โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ select-pane โ selectp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ set-option โ set โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ set-window-option โ setw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ show-options โ show โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ show-window-options โ showw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ split-window โ splitw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ swap-pane โ swapp โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ swap-window โ swapw โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโค โ unlink-window โ unlinkw โ โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโ
If you know the full name of the command, if you were to chop the hyphen (-) from the command and add the first letter of the last word, youรขยยd get the shortcut, e.g., swap-window is swapw, split-window is splitw.
Pattern matching
In addition to aliases, tmux commands and arguments may all be accessed via fnmatch(3) patterns.
For instance, you need not type $ tmux attach-session every time. First, thereรขยยs the alias of $ tmux attach, but additionally, more concise commands can be used if they partially match the name of the command or the target. tmuxรขยยs pattern matching allows $ tmux attac, $ tmux att, $ tmux at and $ tmux a to reach $ tmux attach.
Every tmux command has shorthands; letรขยยs try this for $ tmux new-session:
$ tmux new-session $ tmux new-sessio # ... $ tmux new-s
and so on, until:
$ tmux new- ambiguous command: new-, could be: new-session, new-window
The limitation, as seen above, is command matches can collide. Multiple commands begin with new-. So, if you wanted to use matches, $ tmux new-s for a new session or $ tmux new-w for a new window would be the most efficient way. But, the alias of $ tmux new for new session and $ tmux neww for new windows is even more concise than matching, since the special alias exists.
Patterns can also match targets with window and session names. For instance, a session named mysession can be matched via mys:
Matching targets will fail if a pattern matches more than one item. If 2 sessions exist, named mysession and mysession2, the above command would fail. To target either session, the complete target name must be specified.
Targets
If a command allows target specification, itรขยยs usually done through -t.
Think of targets as tmuxรขยยs way of specifying a unique key in a relational database.
โโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Entity โ Prefix โ Example โ โโโโโโโโโโโชโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ server โ n/a โ n/a, uses socket-name and socket-path โ โโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client โ n/a โ n/a, uses /dev/tty{p,s}[000-9999] โ โโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session โ $ โ $13 โ โโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window โ @ โ @2313 โ โโโโโโโโโโโผโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane โ % โ %5432 โ โโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
What I use to help me remember:
So, sessions are represented by dollar signs ($) because they hold your projects (ostensibly where you make money or help someone else do it).
Windows are represented by the at sign (@). So, windows are like referencing / messaging a user on a social networking website.
Panes are the fun one, represented by the percent sign (%), like the default prompt for csh and tcsh. Hey, makes sense, since panes are pseudoterminals!
When scripting tmux, the symbols help denote the type of object, but also serve as a way to target something deeply, such as the pane, directly, without needing to know or specify its window or session.
Here are some examples of targets, assuming one session named mysession and a client at /dev/ttys004:
attach-session [-t target-session]
$ tmux attach-session -t mysession
detach-client [-s target-session] [-t target-client]
$ tmux detach-client -s mysession -t /dev/ttys004 # If within client, -t is assumed to be current client $ tmux detach-client -s mysession
has-session [-t target-session]
$ tmux has-session -t mysession # Pattern matching session name $ tmux has-session -t mys
$ tmux kill-session [-t target-session]
$ tmux kill-session -t mysession
$ tmux list-clients [-t target-session]
$ tmux list-clients -t mysession
$ tmux lock-client [-t target-client]
$ tmux lock-clients -t /dev/ttys004
$ tmux lock-session [-t target-session]
$ tmux lock-session -t mysession
$ tmux new-session [-t target-session]
$ tmux new-session -t newsession # Create new-session in the background $ tmux new-session -t newsession -d
$ tmux refresh-client [-t target-client]
$ tmux refresh-client -t /dev/ttys004
$ tmux rename-session [-t target-session] session-name
$ tmux rename-session -t mysession renamedsession # If within attached session, -t is assumed $ tmux rename-session renamedsession
$ tmux show-messages [-t target-client]
$ tmux show-messages -t /dev/ttys004
$ tmux suspend-client [-t target-client]
$ tmux suspend-client -t /dev/ttys004 # If already in client $ tmux suspend-client # Bring client back to the foreground $ fg
$ tmux switch-client [-c target-client] [-t target-session]
$ tmux switch-client -c /dev/ttys004 -t othersession # Within current client, -c is assumed $ tmux switch-client -t othersession
Formats
tmux provides a minimal template language and set of variables to access information about your tmux environment.
Formats are specified via the -F flag.
You know how template engines, such as mustache, handlebars ERB in ruby, jinja2 in python, twig in PHP, and JSP in Java, allow template variables? Formats are a similar concept.
The FORMATS (variables) provided by tmux have expanded greatly since version 1.8. Some of the most commonly used formats as of tmux 2.3 are listed below. See the appendix section on formats for a complete list.
Letรขยยs try to output it:
$ tmux list-windows -F "#{window_id} #{window_name}" > @0 zsh
Hereรขยยs a cool trick to list all panes with the x and y coordinates of the cursor position:
$ tmux list-panes -F "#{pane_id} #{pane_current_command} \ #{pane_current_path} #{cursor_x},#{cursor_y}" > %0 vim /Users/me/work/tao-of-tmux/manuscript 0,34 %1 tmux /Users/me/work/tao-of-tmux/manuscript 0,17 %2 man /Users/me/work/tao-of-tmux/manuscript 0,0
Variables are specific to the objects being listed. For instance:
Server-wide variables: host, host_short (no domain name), socket_path, start_time and pid.
Session-wide variables: session_attached, session_activity, session_created, session_height, session_id, session_name, session_width, session_windows and all server-wide variables.
Window variables: window_activity, window_active, window_height, window_id, window_index, window_layout, window_name, window_panes, window_width and all session and server variables.
Pane variables: cursor_x, cursor_y, pane_active, pane_current_command, pane_current_path, pane_height, pane_id, pane_index, pane_width, pane_pid and all window, session and server variables.
This book focuses on separating the concept of server, sessions, windows, and panes. With the knowledge of targets and formats, this separation takes shape in tmuxรขยยs internal attributes. If you list-panes all variables up the ladder, including window, session and server variables are available for the panes being listed. Try this:
$ tmux list-panes -F "pane: #{pane_id}, window: #{window_id}, \ session: #{session_id}, server: #{socket_path}" > pane: %35, window: @13, session: $6, server: /private/tmp/tmux-501/default pane: %38, window: @13, session: $6, server: /private/tmp/tmux-501/default pane: %36, window: @13, session: $6, server: /private/tmp/tmux-501/default
Listing windows isnรขยยt designed to display variables for pane-specific properties. Since a window is a collection of panes, it can have 1 or more panes open at any time.
$ tmux list-windows -F "window: #{window_id}, panes: #{window_panes} \ pane_id: #{pane_id}" > window: @15, panes: 1 pane_id: %40 window: @13, panes: 3 pane_id: %36 window: @25, panes: 1 pane_id: %50
This will show the window ID, prefixed by an @ symbol, and the number of panes inside the window.
Surprisingly, pane_id shows up via list-windows, as of tmux 2.3. While this output occurs in this version of tmux, itรขยยs undefined behavior. Itรขยยs advised to keep use of -F scoped to the objects being listing when scripting to avoid breakage. For instance, if you want the active pane, use #{pane_active} via $ tmux list-panes -F "#{pane_active}".
By default, list-panes will only show panes in a window, unless you specify -a to output all on a server or -s [-t session-name] for all panes in a session:
$ tmux list-panes -s -t mysession > 1.0: [176x29] [history 87/2000, 21033 bytes] %0 1.1: [87x6] [history 1814/2000, 408479 bytes] %1 (active) 1.2: [88x6] [history 1916/2000, 464932 bytes] %2 2.0: [176x24] [history 9/2000, 2262 bytes] %13 2.1: [55x11] [history 55/2000, 7395 bytes] %14
And the -t flag lists all panes in a window:
$ tmux list-panes -t @0 > 0: [176x29] [history 87/2000, 21033 bytes] %0 1: [176x36] [history 1790/2000, 407807 bytes] %1 (active) 2: [88x6] [history 1916/2000, 464932 bytes] %2
The same concept applies to list-windows. By default, The -a flag will list all windows on a server, -t lists windows within a session, and omitting -t will only list windows within the current session inside tmux.
$ tmux list-windows > 1: zsh* (3 panes) [176x36] [layout f9a4,176x36,0,0[176x29,0,0,0,176x6,0,30{87\ x6,0,30,1,88x6,88,30,2}]] @0 (active) 2: zsh- (5 panes) [176x36] [layout 55ef,176x36,0,0[176x24,0,0,13,176x11,0,25{\ 55x11,0,25,14,58x11,56,25[58x7,56,25,16,58x3,56,33,17],61x11,115,25,15}]] @6
Controlling tmux
tmux allows sending keys, including Ctrl via C- or ^, alt (Meta) via M-, and special key names. Hereรขยยs a list of special keys straight from the manual:
Up, Down, Left, Right, BSpace, BTab, DC (Delete), End, Enter, Escape, F1 to F12, Home, IC (Insert), NPage/PageDown/PgDn, PPage/PageUp/PgUp, Space, and Tab.
If special keys are not matched, the defined behavior is to send it as a string to the pane, character by character.
For this example, we will use send-keys through tmux prompt, because omitting target (-t) will direct the command to the current pane, but the keys sent will sometimes print before the prompt.
Open tmux command prompt via Prefix + : and type this after the ::
send-keys echo 'hi'
Hit enter. This inserted hi into the current active pane. You can also use targets to specify which pane to send it to.
Letรขยยs now try to send keys to another pane in our current window. Create a second pane via splitting the window if one doesnรขยยt exist. You can also do this exercise outside of tmux or inside a scripting file and running it.
Grab a pane ID from the output of list-panes:
$ tmux list-panes > 0: [180x57] [history 87/2000, 21033 bytes] %0 1: [89x14] [history 1884/2000, 509864 bytes] %1 (active) 2: [90x14] [history 1853/2000, 465297 bytes] %2
%2 looks good. Replace %2 with the pane you want to target. This sends cal to the input:
$ tmux send-keys -t %2 'cal'
Nice, letรขยยs cancel that out by sending a SIGINT:
$ tmux send-keys -t %2 'C-c'
This cancelled the command and brought up a fresh input. This time, letรขยยs send an Enter keypress to run cal(1).
$ tmux send-keys -t %2 'cal' 'Enter'
This outputs in the adjacent pane.
Top-left: Listing panes, Bottom-left: Sending keys to right pane, Right: Output of cal(1). ๐ท
Top-left: Listing panes, Bottom-left: Sending keys to right pane, Right: Output of cal(1).
Capturing pane content
$ tmux capture-pane will copy a panesรขยย contents.
By default, the contents will be saved to tmuxรขยยs internal clipboard, the paste buffer. You can run capture-pane within any pane, then navigate to an editor, paste the contents (donรขยยt forget to :set paste and go into insert mode with i in vim), and save it to a file. To paste, use Prefix + ] inside the pane youรขยยre pasting into.
You can also add the -p flag to print it to stdout. From there, you could use redirection to place the output into a file. Letรขยยs do >> so we donรขยยt accidentally truncate a file:
$ tmux capture-pane -p >> ./test
As an alternative to redirection, you can also use save-buffer. The -a flag will get you the same behavior as appended output direction.
$ tmux save-buffer -a ./test
To check whatรขยยs inside:
Like with send-keys, targets can be specified with -t. Letรขยยs copy a pane into tmuxรขยยs clipboard (รขยยpaste bufferรขยย) and paste it into a text editor in a third pane:
Top-left: Listing panes, Bottom-left: Capturing pane output of top-left pane, Right: Pasting buffer into vim.
Remember, you can also copy, paste, and send-keys to other windows and sessions also. Targets are server-wide.
Summary
tmux has a well-devised and intuitive command system, enabling the user to access bread and butter functionality quickly. At the same time, tmux provides a powerful way of retrieving information on its objects between list-panes, list-windows and list-sessions and formats. This makes tmux not only accessible and configurable, but also scriptable.
The ability to retrieve explicitly and reliably, from a session down to a pane. All it takes is a paneรขยยs ID to capture its contents or even send it keys. Used by the skilled programmer, scripting tmux can facilitate orchestrating terminals in ways previously deemed unrealistic; anything from niche shell scripts to monitor and react to behavior on systems to high-level, intelligent and structured control via object oriented libraries, like libtmux.
In the next chapter, we delve into optimizations that showcase the latest generation of unix tools that build upon old, time-tested concepts, like man pages and piping, while maintaining portability across differences in platforms and graceful degradation to ensure development tooling works on machines missing optional tools. Also, the chapter will introduce session managers, a powerful, high-level tool leveraging tmuxรขยยs scripting capabilities to consistently load workspace via a declarative configuration.
11. Tips and tricks
--------------------------------------------------------------------------------
Read the tmux manual in style
$ man tmux is the command to load up the man page for tmux. You can do the same to find instructions for any command or entity with a manpage entry; here are some fun ones:
$ man less $ man man $ man strftime
most(1), a solid PAGER, drastically improves readability of manual pages by acting as a syntax highlighter.
left: man, version 1.6c on macOS Sierra. right: MOST v5.0.0 ๐ท
left: man, version 1.6c on macOS Sierra. right: MOST v5.0.0
To get this working, you need to set your PAGER environmental variable to point to the MOST binary. You can test it like this:
If you found you like most, youรขยยll probably want to make it your default manpage reader. You can do this by setting an environmental variable in your รขยยrcรขยย (Run Commands) for your shell. The location of the file depends on your shell. You can use $ echo $SHELL to find it on most shells). In Bash and zsh, these are kept in ~/.bashrc or ~/.zshrc, respectively:
I often reuse my configurations across machines, and some of them may not have most installed, so I will have my scripting only set PAGER if most is found:
#!/bin/sh if command -v most > /dev/null 2>&1; then export PAGER="most" fi
Save this in a file, for example, to ~/.dot-config/most.sh.
Then you can source it in via your main rc file.
source $HOME/.dot-config/most.sh
Patterns like these help make your dot-configs portable, cross-platform, and modular. For inspiration, you can fork, copy, and paste from my permissively- licensed config at https://github.com/tony/.dot-config.
https://github.com/tony/.dot-config
Log tailing
Not tmux specific, but powerful when used in tandem with it, you can run a follow (-f) using tail(1). More modern versions of tail have the -F (capitalized), which checks for file renames and rotation.
On OS X, you can do:
$ tail -F /var/log/system.log
and keep it running in a pane while log messages come in. Itรขยยs like Facebook newsfeed for your system, except for programmers and system administrators.
For monitoring logs, multitail provides a terminal-friendly solution. Itรขยยd be an Inception moment, because youรขยยd be using a log multiplexer in a terminal multiplexer.
File watching
In my never-ending conquest to get software projects working in symphony with code changes, Iรขยยve come to test many file watching applications and patterns. Pursuing the holy grail feedback loop upon file changes, Iรขยยve gradually become the internetรขยยs unofficial connoisseur on them.
File watcher applications wait for a file to be updated, then execute a custom command, such as restarting a server, rebuilding an application, running tests, linters, and so on. It gives you, as a developer, instant feedback in the terminal, empowering a tmux workspace to have IDE-like features, without the bloat, memory, and CPU fans roaring.
I eventually settled on entr(1), which works superbly across Linux distros, BSDs and OS X / macOS.
The trick to make entr work is to pipe a list of files into it to watch.
Letรขยยs search for all .go files in a directory and run tests on file change:
$ ls -d *.go | entr -c go test ./...
Sometimes, we may want to watch files recursively, but we need it to run reliably across systems. We canรขยยt depend on ** existing to grab files recursively, since itรขยยs not portable. Something more POSIX-friendly would be find . -print | grep -i '.*[.]go':
$ find . -print | grep -i '.*[.]go' | entr -c go test ./...
To only run file watcher if entr is installed, letรขยยs wrap in a conditional command -v test:
$ if command -v entr > /dev/null; then find . -print | grep -i '.*[.]go' | \ entr -c go test ./...; fi
And have it fallback to go test in the event entr isnรขยยt installed. This allows your command to degrade gracefully. Youรขยยll thank me when you use this snippet in conjunction with a session manager:
$ if command -v entr > /dev/null; then find . -print | grep -i '.*[.]go' | \ entr -c go test ./...; else go test ./...; fi
If the project is a team or open source project, where a user never used the command before and could be missing a required software package, we can give a helpful message. This shows a notice to the user to install entr if not installed on the system:
$ if command -v entr > /dev/null; then find . -print | grep -i '.*[.]go' | \ entr -c go test ./...; else go test ./...; echo "\nInstall entr(1) to \" echo "run tasks when files change. \nSee http://entrproject.org/"; fi
Hereรขยยs why you want patterns like above: You can put it into a Makefile and commit it to your projectรขยยs VCS, so you and other developers can have access to this reusable command across different UNIX-like systems, with and without certain programs installed.
Note: You may have to convert the indentation within the Makefiles from spaces to tabs.
Letรขยยs see what a Makefile with this looks like:
watch_test: if command -v entr > /dev/null; then find . -print | grep -i '.*[.]go' | en\ tr -c go test ./...; else go test ./...; echo "\nInstall entr(1) to run tasks w\ hen files change. \nSee http://entrproject.org/"; fi
To run this, do $ make watch_test in the same directory as the Makefile.
But itรขยยs still a tad bloated and hard to read. We have a couple tricks at our disposal. One would be to add continuation to the next line with a trailing backslash (\):
watch_test: if command -v entr > /dev/null; then find . -print | \ grep -i '.*[.]go' | entr -c go test ./...; \ else go test ./...; \ echo "\nInstall entr(1) to run tasks on file change. \n"; \ echo "See http://entrproject.org/"; fi
Another would be to break the command into variables and make subcommands. So:
WATCH_FILES= find . -type f -not -path '*/\.*' | \ grep -i '.*[.]go$' 2> /dev/null test: go test $(test) ./... entr_warn: @echo "-------------------------------------------------" @echo " ! File watching functionality non-operational ! " @echo " " @echo " Install entr(1) to run tasks on file change. " @echo " See http://entrproject.org/ " @echo "-------------------------------------------------" watch_test: if command -v entr > /dev/null; then ${WATCH_FILES} | \ entr -c $(MAKE) test; else $(MAKE) test entr_warn; fi
$(MAKE) is used for portability. One reason is recursive calls, such as here. On BSD systems, you may try invoking make via gmake (to call GNU Make specifically). This happened to me, while building PDFs for the book AlgoXY. I had to write a patch to make it properly use $(MAKE) for recursive calls.
The $(test) after go test allows passing a shell variable with arguments in it. So, you could do make watch_test test='-i'. For examples of a similar Makefile in action, see the one in my tmuxp project. The project is licensed BSD (permissive), so you can grab code and use it in compliance with the LICENSE.
One more thing, letรขยยs say youรขยยre running a server, like Gin, Iris, or Echo. entr -c likely wonรขยยt be restarting the server for you. Try entering the -r flag to send a SIGTERM to the process before restarting it. Combining the current -c flag with the new -r will give you entr -rc:
run: go run main.go watch_run: if command -v entr > /dev/null; then ${WATCH_FILES} | \ entr -c $(MAKE) run; else $(MAKE) run entr_warn; fi
Session Managers
For those who use tmux regularly to perform repetitive tasks, such as opening the same software project, viewing the same logs, etc., frequent tasks will often lead to the creation of tmux scripts.
A user can use plain shell scripting to build their tmux sessions. However, scripting is error prone, hard to debug, and requires tmux to split windows into panes in a certain order. In addition, thereรขยยs the burden of assuring the shell scripts are portable.
A declarative configuration in YAML or JSON configuration abstracts out the commands, layout, and options of tmux. It prevents the mistakes and repetition scripting entails. These applications are called tmux session managers, and in different ways, they programmatically create tmux workspaces by running a series of commands based on a config.
Teamocil and Tmuxinator are the first ones I tried. By far, the most popular one is tmuxinator. They are both programmed in Ruby. Thereรขยยs also tmuxomatic, where you can รขยยdrawรขยย your tmux sessions in text and have tmuxomatic build the layout.
I sort of have a home team advantage here, as Iรขยยm author of tmuxp. Already having used teamocil and tmuxinator, I wrote my own in python instead of ruby, with many more features. For one, it builds on top of libtmux, a library which abstracts tmux server, sessions, windows and panes to build the state of tmux sessions. In addition, it has a naive form of session freezing, support for JSON, more flexible configuration options, and it will even offer to attach exiting sessions, instead of redundantly running script commands against the session if itรขยยs already running.
So, in tmuxp, weรขยยll hollow out a tmuxp config directory with $ mkdir ~/.tmuxp then create a YAML file at ~/.tmuxp/test.yaml:
session_name: 4-pane-split windows: - window_name: dev window layout: tiled shell_command_before: - cd ~/ # run as a first command in all panes panes: - shell_command: # pane no. 1 - cd /var/log # run multiple commands in this pane - ls -al | grep \.log - echo second pane # pane no. 2 - echo third pane # pane no. 3 - echo forth pane # pane no. 4
gives a session titled 4-pane-split, with one window titled dev window with 4 panes in it. 3 in the home directory; the other is in /var/log and is printing a list of all files ending with .log.
To launch it, install tmuxp and load the configuration:
$ pip install --user tmuxp $ tmuxp -V # verify tmuxp is installed, if not you need to fix your `PATH` # to point to your python bin folder. More help below. $ tmuxp load ~/.tmuxp/test.yaml
If tmuxp isnรขยยt found, there is a troubleshooting entry on fixing your paths in the appendix.
More code and examples
Iรขยยve dusted off a C++ space shooter and a new go webapp Iรขยยve been playing with. Theyรขยยre licensed under MIT so, you can use them, copy and paste from them, etc:
Both support tmuxp load . within the project directory to load up the project.
Make sure to install entr(1) beforehand!
tmux-plugins and tpm
tmux-plugins and tmux package manager are a suite of tools dedicated to enhancing the experience of tmux users.
manager
tmux environment across system restarts.
saving of tmux environment. Automatic restore when tmux is started. Automatic tmux start when computer is turned on.
copying to system clipboard. Works on OSX, Linux and Cygwin.
battery percentage and icon indicator for Tmux.
12. Takeaway
--------------------------------------------------------------------------------
In this book, weรขยยve taken an organized approach to understanding tmux. As you use tmux more and more, continue to come back and use this resource to help wrap your brain around concepts. You do not have to understand the intricacies of tmux, let alone the terminal, in a single sitting. Acclimation happens over time.
tmuxรขยยs userbase varies in skill level. Some readers of this book may have just learned how to use the Prefix key yesterday. Others are looking to tweak their configurations and host it in their รขยยdot filesรขยย on github. There also exists a very clever hacker who utilizes the advanced scripting capabilities tmux offers to pilot the terminal in ways previously thought impossible.
Weรขยยve covered the server, session, window, and pane concepts. Panes are shells, AKA pseudoterminals or PTYs. The command system. That configuration is basically a file filled with commands. An overview of the target system lets you specify objects to interact with tmux commands. A breeze through formats, a template system with variables to retrieve information on tmuxรขยยs current state. How to send keystrokes and copy from tmux panes programmatically. A lot of terminal tricks that work across platforms and well with tmux, including a file watching workflow to run linting, testing, and build commands on file changes. Two permissively licensed open source projects for demonstration. A tmux configuration you can copy and paste from. An object oriented tmux API wrapper and a tmux session manager.
If you liked this book, please leave a review on Amazon and Goodreads. I would also appreciate you leaving something in my tip jar. I am an independent software developer and could use all the help I can get.
If you found an error or have a suggestion, please contact me at tao.of.tmux@git-pull.com. I want this book to be the best it can be. If you are having technical difficulties with Kindle, please send me your receipt and I will comp you a leanpub coupon.
These are taken directly from tmuxรขยยs manual pages, tabled and organized by hand into sections for convenience.
Commands
Session
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Command โ Action โ โโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ no command โ Short-cut for new-session โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ attach-session โ Attach or switch to a session โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ choose-session โ Put a window into session choice mode โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ has-session โ Check and report if a session exists on the server โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ kill-session โ Destroy a given session โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ list-sessions โ List sessions managed by server โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ lock-session โ Lock all clients attached to a session โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ new-session โ Create a new session โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ rename-session โ Rename a session โ โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Window
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Command โ Action โ โโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ choose-window โ Put a window into window choice โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ find-window โ Search for a pattern in windows โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ kill-window โ Destroy a given window โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ last-window โ Select the previously selected โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ link-window โ Link a window to another โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ list-windows โ List windows of a session โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ move-window โ Move a window to another โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ new-window โ Create a new window โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ next-window โ Move to the next window in a sesssion โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ previous-window โ Move to the previous window in session โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ rename-window โ Rename a window โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ respawn-window โ Reuse a window in which a command has exited โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ rotate-window โ Rotate positions of panes in a window โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ select-window โ Select a window โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ set-window-option โ Set a window option โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ show-window-options โ Show window options โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ split-window โ Splits a pane into two โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ swap-window โ Swap two windows โ โโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ unlink-window โ Unlink a window โ โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Pane
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Command โ Action โ โโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ break-pane โ Break a pane from an existing into a new window โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ capture-pane โ Capture the contents of a pane to a buffer โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ display-panes โ Display an indicator for each visible pane โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ join-pane โ Split a pane and move an existing one into the new space โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ kill-pane โ Destroy a given pane โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ last-pane โ Select the previously selected pane โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ list-panes โ List panes of a window โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ move-pane โ Move a pane into a new space โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pipe-pane โ Pipe output from a pane to a shell command โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ resize-pane โ Resize a pane โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ respawn-pane โ Reuse a pane in which a command has exited โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ select-pane โ Make a pane the active one in the window โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ swap-pane โ Swap two panes โ โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Keybindings
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ C-b โ Send the prefix key (C-b) through to the โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ application. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Miscellaneous
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ C-z โ Suspend the tmux client. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ r โ Force redraw of the attached client. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ t โ Show the time. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ~ โ Show previous messages from tmux, if any. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ f โ Prompt to search for text in open windows. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ d โ Detach the current client. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ D โ Choose a client to detach. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ? โ List all key bindings. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ : โ Enter the tmux command prompt. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Copy/Paste
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ # โ List all paste buffers. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ [ โ Enter copy mode to copy text or view the history. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ] โ Paste the most recently copied buffer of text. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Page Up โ Enter copy mode and scroll one page up. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ = โ Choose which buffer to paste interactively from a โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ list. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ - โ Delete the most recently copied buffer of text. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Session
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ $ โ Rename the current session. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Session Traversal
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ L โ Switch the attached client back to the last โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ session. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ s โ Select a new session for the attached client โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ interactively. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Window
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ c โ Create a new window. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ & โ Kill the current window. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ i โ Display some information about the current window. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ , โ Rename the current window. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Window Traversal
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ 0 to 9 โ Select windows 0 to 9. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ w โ Choose the current window interactively. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ M-n โ Move to the next window with a bell or activity โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ marker. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ M-p โ Move to the previous window with a bell or activity โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโค โ ร โ marker. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ p โ Change to the previous window. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ n โ Change to the next window. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ l โ Move to the previously selected window. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ' โ Prompt for a window index to select. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Window Moving
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ . โ Prompt for an index to move the current window โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Pane
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ x โ Kill the current pane. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ q โ Briefly display pane indexes. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ % โ Split the current pane into two, left and right. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ " โ Split the current pane into two, top and bottom. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Pane Traversal
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ ; โ Move to the previously active pane. โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Up, Down โ Change to the pane above, below, to the left, or to โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ Left, Right โ the right of the current pane. โ โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ o โ Select the next pane in the current window. โ โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Pane Moving
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ C-o โ Rotate the panes in the current window forwards. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ M-o โ Rotate the panes in the current window backwards. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ { โ Swap the current pane with the previous pane. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ } โ Swap the current pane with the next pane. โ โโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ! โ Break the current pane out of the window. โ โโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Pane Resizing
โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Shortcut โ Action โ โโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ M-1 to M-5 โ Arrange panes in one of the five preset layouts: โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ even-horizontal, even-vertical, main-horizontal, โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ main-vertical, or tiled. โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ C-Up, C-Down โ Resize the current pane in steps of one cell. โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ C-Left, C-Right โ ร โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ M-Up, M-Down โ Resize the current pane in steps of five cells. โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ M-Left, M-Right โ ร โ โโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Formats
Copy / paste
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ buffer_name โ Name of buffer โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ buffer_sample โ Sample of start of buffer โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ buffer_size โ Size of the specified buffer in bytes โ โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Clients
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ client_activity โ Integer time client last had activity โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_created โ Integer time client created โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_control_mode โ 1 if client is in control mode โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_height โ Height of client โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_key_table โ Current key table โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_last_session โ Name of the clientรขยยs last session โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_pid โ PID of client process โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_prefix โ 1 if prefix key has been pressed โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_readonly โ 1 if client is readonly โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_session โ Name of the clientรขยยs session โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_termname โ Terminal name of client โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_tty โ Pseudo terminal of client โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_utf8 โ 1 if client supports utf8 โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ client_width โ Width of client โ โโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ line โ Line number in the list โ โโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Panes
โโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ alternate_on โ If pane is in alternate screen โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ alternate_saved_x โ Saved cursor X in alternate screen โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโค โ alternate_saved_y โ Saved cursor Y in alternate screen โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ cursor_flag โ Pane cursor flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ cursor_x โ Cursor X position in pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ cursor_y โ Cursor Y position in pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ insert_flag โ Pane insert flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ keypad_cursor_flag โ Pane keypad cursor flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ keypad_flag โ Pane keypad flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ mouse_any_flag โ Pane mouse any flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ mouse_button_flag โ Pane mouse button flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ mouse_standard_flag โ Pane mouse standard flag โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_active โ 1 if active pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_bottom โ Bottom of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_current_command โ Current command if available โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_current_path โ Current path if available โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_dead โ 1 if pane is dead โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_dead_status โ Exit status of process in dead pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_height โ Height of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_id โ Unique pane ID (Alias: #D) โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_in_mode โ If pane is in a mode โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_input_off โ If input to pane is disabled โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_index โ Index of pane (Alias: #P) โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_left โ Left of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_pid โ PID of first process in pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_right โ Right of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_start_command โ Command pane started with โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_synchronized โ If pane is synchronized โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_tabs โ Pane tab positions โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_title โ Title of pane (Alias: #T) โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_top โ Top of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_tty โ Pseudo terminal of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pane_width โ Width of pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ scroll_region_lower โ Bottom of scroll region in pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ scroll_region_upper โ Top of scroll region in pane โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ scroll_position โ Scroll position in copy mode โ โโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ wrap_flag โ Pane wrap flag โ โโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Sessions
โโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ session_alerts โ List of window indexes with alerts โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_attached โ Number of clients session is attached to โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_activity โ Integer time of session last activity โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_created โ Integer time session created โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_last_attached โ Integer time session last attached โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_group โ Number of session group โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_grouped โ 1 if session in a group โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_height โ Height of session โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_id โ Unique session ID โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_many_attached โ 1 if multiple clients attached โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_name โ Name of session (Alias: #S) โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_width โ Width of session โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ session_windows โ Number of windows in session โ โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Windows
โโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ history_bytes โ Number of bytes in window history โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ history_limit โ Maximum window history lines โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ history_size โ Size of history in bytes โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_activity โ Integer time of window last activity โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_activity_flag โ 1 if window has activity โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_active โ 1 if window active โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_bell_flag โ 1 if window has bell โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_find_matches โ Matched data from the find-window โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_flags โ Window flags (Alias: #F) โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค ๏ฟฝ๏ฟฝ window_height โ Height of window โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_id โ Unique window ID โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_index โ Index of window (Alias: #I) โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_last_flag โ 1 if window is the last used โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_layout โ Window layout description, ignoring zoomed โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ window panes โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_linked โ 1 if window is linked across sessions โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_name โ Name of window (Alias: #W) โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_panes โ Number of panes in window โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_silence_flag โ 1 if window has silence alert โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_visible_layout โ Window layout description, respecting โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ zoomed window panes โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_width โ Width of window โ โโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ window_zoomed_flag โ 1 if window is zoomed โ โโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Servers
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ host โ Hostname of local host (alias: #H) โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ host_short โ Hostname of local host (no domain name) โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ ร โ (alias: #h) โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ socket_path โ Server socket path โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ start_time โ Server start time โ โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ pid โ Server PID โ โโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Commands
For $ tmux list-commands.
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ Variable name โ Description โ โโโโโโโโโโโโโโโโโโโโโโชโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโก โ command_hooked โ Name of command hooked, if any โ โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ command_name โ Name of command in use, if any โ โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ command_list_name โ Command name if listing commands โ โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ command_list_alias โ Command alias if listing commands โ โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค โ command_list_usage โ Command usage if listing commands โ โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
macOS / OS X
brew
macports
fink
Linux
Ubuntu / Mint / Debian, etc.
$ sudo apt-get install tmux
CentOS / Fedora / Redhat, etc.
Arch Linux (pacman)
Gentoo (portage)
$ sudo emerge --ask app-misc/tmux
BSD
FreeBSD
pkg(1)
pkg_add(1)
OpenBSD
As of OpenBSD 4.6, tmux is part of the base system.
tmux is part of the base system
If you are using an earlier version:
NetBSD
$ make -C /usr/pkgsrc/misc/tmux install
Windows 10
Check out the tmux on Windows 10 appendix section.
As of Windows 10 build 14361, you can run tmux via the Linux Subsystem feature.
Usage requires enabling Developer mode via the รขยยFor Developersรขยย tab in the รขยยUpdate & securityรขยย settings.
After enabling, open รขยยWindows Featuresรขยย. You can find it by searching for รขยยTurn Windows features on or offรขยย. Then check รขยยWindows Subsystem for Linux (Beta)รขยย.
You may be asked to restart.
Then open Command Prompt as you normally would (Run cli.exe). Then type
It will prompt you to agree to terms, create a user. In my build, tmux was already installed! But if itรขยยs not, type sudo apt-get install tmux.
Find Turn Windows Features on or off ๐ท
Find Turn Windows Features on or off
Check Windows Subsystem for Linux (Beta) ๐ท
Check Windows Subsystem for Linux (Beta)
Windows completed the requested changes. Restart ๐ท
Windows completed the requested changes. Restart
Use Developer features
Select Developer mode in Update & Security ๐ท
Select Developer mode in Update & Security
Installing Ubuntu from Windows Store ๐ท
Installing Ubuntu from Windows Store
Create Linux user
In bash!
yourusername@COMPUTERNAME-ID321FJ:/mnt/c/Users/username$ tmux
In tmux!
This should allow you to run tmux within bash.exe.
This is a real ubuntu installation, so you can continue to install packages via sudo apt-get install **packagename** and update packages via sudo apt-get update && sudo apt-get upgrade.
E353: Nothing in register * when pasting on vim
If you are using macOS / OS X with vim inside tmux, you may get the error E353: Nothing in register * when trying to paste.
Try installing reattach-to-user-namespace via brew.
$ brew install reattach-to-user-namespace
tmuxp: command not found and powerline: command not found
This is due to your site package bin path (where application entry points are installed) not being in your paths. To find your user site packages base directory:
$ python -m site --user-base
This will get you something like /Users/me/Library/Python/2.7 on macOS with Python 2.7 or /home/me/.local on Linux/BSD boxes.
The applications are in the bin/ folder inside. So, concatenate the two and apply them to your PATH. This can be done automatically on every shell session by using one of these in your ~/.bashrc or ~/.zshrc:
export PATH=/Users/me/Library/Python/2.7/bin:$PATH # macOS w/ python 2.7 export PATH=$HOME/.local/bin:$PATH # Linux/BSD export PATH="`python -m site --user-base`/bin":$PATH # May work all-around
Then open a new terminal, or . ~/.zshrc / . ~/.bashrc in your current one. Then you can run $ tmuxp -V, $ tmuxp load and $ powerline tmux right commands.