iTerm and Tmux, sitting in a tree.

A lesser known trick of iTerm 2 is that it has some pretty swish tmux integration. For most of us, we know that terminal multiplexers like tmux and screen solve a lot of problems like:

  • Restoring terminal sessions that have died due to:
    • Network issues
    • Putting your laptop to sleep in the middle of a long running command
    • iTerm crashing, although rare, it happened to me once
  • Sharing a terminal with another remote user
  • Splitting the screen to see 2 things at once

One of the annoying things about terminal multiplexers is that scrolling to previous history isn’t as simple as a quick trackpad flick.

Behold, the magic:

# Start a new tmux session
$ tmux -CC
# Resume a previous tmux sessions
$ tmux -CC attach

The magic, is the -CC. iTerm will start a new tmux session and your terminal will now look like this:

** tmux mode started **
Command Menu
esc    Detach cleanly.
  X    Force-quit tmux mode.
  L    Toggle logging.
  C    Run tmux command.

If this was a new session you’d have a new window pop up that is a tmux session. The window acts like you’d expect. Opening a new tab in fact opens a new tmux window. You can also split panes, resize windows and panes and many other things.

If you tmux -CC attach, it opens up your previous window exactly as it was before.

It’s lovely, yummy and brilliant. Enjoy!

Spread the word

twitter icon facebook icon linkedin icon