Ramblings of an aging IT geek
← Ramblings of an aging IT geek
tooling

tmux, and the day i stopped losing my work to a dropped ssh

How I actually use tmux day to day, the handful of bindings that earn their keep, and why detach is the only feature that really matters.

A mechanical keyboard lit by a terminal

The moment tmux earned its place was a train somewhere past Reading, a long-running migration, and a 4G signal that came and went like a polite ghost. SSH dropped. The migration didn't, because it was running inside a tmux session on the far end, and when the signal came back I typed tmux attach and there it was, mid-scroll, exactly where I'd left it. That's the whole pitch. Everything else is convenience.

Detach is the feature

If you take one thing from tmux, take this: your shell session lives on the server, not in your terminal emulator. You attach to it and detach from it. The network can fall over, your laptop can sleep, you can close the lid and walk to lunch, and the work keeps going. Ctrl-b d to detach on purpose; a dropped connection detaches you for free.

I start named sessions so I can find them again:

tmux new -s migration
# ... later, from anywhere ...
tmux attach -t migration
tmux ls   # what have I left running?

Code on a screen, panes side by side

The bindings I actually use

I haven't memorised the manual. I use maybe six things, and they cover ninety percent of the work:

  • Ctrl-b " and Ctrl-b % to split a window into stacked or side-by-side panes.
  • Ctrl-b o to cycle panes, Ctrl-b z to zoom one to full screen and back.
  • Ctrl-b c for a new window, Ctrl-b , to rename it so I'm not staring at a row of bash bash bash.
  • Ctrl-b [ to enter copy mode and scroll back through output without a mouse.

A small config that helps

The default prefix is fine, but two changes pay for themselves. I turn on the mouse so I can resize panes by dragging when I'm being lazy, and I bump the scrollback history because the default runs out exactly when you need the line that scrolled off.

set -g mouse on
set -g history-limit 50000
set -g base-index 1
setw -g pane-base-index 1

That base-index 1 is pure pettiness: it makes the first window number 1 instead of 0, so the window numbers line up with the number row on the keyboard. Small thing. Annoyed me for years before I fixed it.

I'm not running anything exotic on top, no resurrect plugin, no themed status bar with the weather in it. The value was never in the decoration. It was in the train, and the dropped connection, and the migration that didn't care.