tmux, where have you been?

Mark Lin
LifeOps — One problem at a time.
3 min readAug 7, 2019

My first system admin job was dealing with Sun Solaris. At that time, I learned to rely on most basic tools because sometimes, only most basic tools are available. I picked vi over emacs because it’s more available. I did bumped into situation where even vi wasn’t available to change a file in single user mode, only ed was. Ed is a line editor, no full screen editing, just one line, that came with Unix operating system when it was first developed, 1969.

This is just to show my “upbringing” as system admin. Use simplest tool to get stuff done, rely on default setup instead of customization. Of course, the world has moved on, but little bit of that mentality is still in me.

As sys admin, I use terminal a lot. I know utility like “screen” that does session switching and window splitting. But since I deal with unix a lot, with screen using Ctrl+a to initiate screen command, it collides with same command for jumping to beginning of command line. It was annoyed enough to abandon screen. I am sure one can switch Ctrl-a to something else, but screen’s benefit doesn’t seem worth the effort and I tend to rely on default instead of customization.

19 years later, couple days ago, I saw a friend’s terminal window with 4 evenly split panes each with a session in it. He was able to run application in one and see output in another and tailing logs on third one without switching tabs or windows. It doesn’t look like it’s screen, too fancy. I was intrigued.

Tmux, as I was told, is terminal multiplexer. It’s similar to screen to maintain session and split windows and most important of all, its default command key is Ctrl+b. A key sequence I don’t remember ever used on Mac. That means it wouldn’t interfere with existing muscle memory. I was sold.

Installation reference:

Long story short. Now I have multiple windows each with its own panes layout that’s customized for each client/project.

tmux screenshot
tmux window selection

What’s cool about tmux is that it can work with mouse to activate pane, scroll, and select text for copy. It’s kinda mind bender, a text-based utility that can work with mouse to adjust its history and pane size.

To install session restore follow

My own ~/.tmux.conf has mouse enable and vi copy mode enable

set -g @plugin ‘tmux-plugins/tmux-resurrect’
set -g @plugin ‘tmux-plugins/tmux-continuum’
# Disable status bar
set -g status off
# Longer history
set -g history-limit 5000
# Restore saved session
set -g @continuum-restore ‘on’
# Set to vi mode
setw -g mode-keys vi
# Enable mouse support version 2.1+
setw -g mouse on
unbind -T copy-mode-vi MouseDragEnd1Pane
bind P paste-buffer
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind -T copy-mode-vi y send -X copy-pipe “reattach-to-user-namespace pbcopy”\; display-message “copied to
system clipboard”
bind-key -T copy-mode-vi r send-keys -X rectangle-toggle
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b ‘~/.tmux/plugins/tpm/tpm’

That’s it. Install tmux, install the plugin, configure with .tmux.conf and learn a few quick key strokes, you now have a super flexible terminal.

One thing I haven’t figured out is selecting text and copy. With current config, once text is selected, I can press ‘y’ or hit enter to copy the text. But hitting ‘y’ would not turn off text highlighting. Press enter will copy the text but jump out of buffer mode. I wanted the same behavior as rest of Mac copy, highlight text, Cmd+c, text copied, highlight disappear and screen stay where it it.

All in all, I haven’t felt this excited about terminal since….ever. Happing tmux’ing.

--

--