tmux
June 11, 2020 — October 25, 2024
tmux
is functionally a combination of abduco
and dvtm
into one baffling but useful terminal session manager.
On one hand, it is easy because it is so popular and thus documented everywhere, and installed most places. On the other, it is confusing and has weird terminology, so we need all that documentation to work out what I just did.
A neat feature of tmux
is that it has a magical integration with iterm2 on macOS in “control centre” mode. This makes usage more intuitive by recycling the terminal GUI for handling session management. However, integration is controversial and does not seem supported widely across other terminal emulators.
Here are some intros to tmux
: 0 1, 2 and a cheat sheet. Terminology is confusing. tl;dr: It creates “sessions” which seem to be connections to a host, which contain “windows”, which are virtual terminals within that session. Both these persist if you log in or out.
1 World’s shortest introduction
- Create new windows (which are virtual terminals)
-
Ctrl-b c
- Previous/next window
-
Ctrl-b p
/C-b n
2 Scrolling, mousing
2.1 Scrolling AHHHHH!
Once I had used tmux for a while I discovered I wished to do backwards scrolling and it did not by default work with a mouse. There are various keyboard shortcuts, and a mouse mode enabling scrolling (set -g mouse on
in ~/.tmux.conf
, or Ctrl-b: set mouse on
if I forgot to create the config file). tmux mouse mode is not great IMO. It tries to be way too clever. Sometimes it scrolls back through command history, which is downright evil. Why would I want this app, alone of all in the universe, to do such a stupid thing? When do I want my search back through something so precise as system commands to be a kinetic slalom? Probably there is some keyboard shortcut which causes the mouse scrolling to turn evil, no idea which one; I just want this thing to do its best to pretend to be the normal terminal and not try to do clever shit at me. All tips on killing that with fire gratefully accepted.
2.2 Oh no now copy is broken
You would like to copy stuff from terminal? tl;dr shift clicking probably does what you want.
long version: Mouse mode breaks copy-paste in that it only copy-pastes into a tmux internal buffer, not into the global clipboard. I am sure this feature suits someone out there, but not me, because I also use non-terminal apps, The workarounds listed at that link do not seem to work on remote terminals. Possibly installing plugins helps, e.g. tmux-plugins/tmux-yank.
Here is a configuration that laboriously restores normalcy: Copy and Paste in tmux.
This is quite tedious to set up. In fact, I find it easier to take a screenshot of my terminal and then run OCR on it.
In macOS with vscode the setting integrated.macOptionClickForcesSelection: true
allows us to select text in the terminal using option+click
when selecting text.
2.3 Now quitting tmux causes pain
If the mouse scroll mode causes things to break after quitting tmux, and now clicking on the window causes this kind of crap: 0;38;15M 0;38;15m 0;60;12M0;60;12m0;56;14M0;56;14m0;56;14M0;56;14m0;54;13M0;54;13m0;54;13M0;54;13m
… eek! Running reset
puts things right in some circumstances. Other times (e.g. in hyper) reloading the terminal from the app window is necessary (Ctrl-Shift-R
).
3 Ecosystem
There are various other tools in the ecosystem, e.g. tmuxinator is a config tool for tmux.
4 Byobu
Byobu is a GPLv3 open source text-based window manager and terminal multiplexer.… Byobu now includes enhanced profiles, convenient keybindings, configuration utilities, and toggle-able system status notifications for both the GNU Screen window manager and the more modern Tmux terminal multiplexer, and works on most Linux, BSD, and Mac distributions.
byobu uses (by default) one socket you can designate a particular socket and share ‘write’ permission with another users and BAM you have multi-session multi-user work for any application that can run a terminal
Question: since tmux
can already work over named sockets, can tmux
do this without special treatment from byobu
?