Hacker News new | ask | show | jobs
by piratebroadcast 3737 days ago
Serious Question: Why would I want to use Tmux instead of iTerm with multiple tabs open? I don't think I get it. Can anyone ELI5?
7 comments

It is significantly more powerful. With key bindings you control or scripts you write, you can move/split/combine your tabs/panes/windows in any way you can imagine, which for me is more ways than iTerm allows.

Ever SSH into the same machine twice? Put tmux on your servers. Or use it to leave jobs running and check on them later.

Edit: Almost forgot. If you use a console editor like Vim or Emacs (well, Emacs people probably do this all inside Emacs) you can basically build-your-own IDE by running arbitrary code in tmux panes (again, your imagination is the limit here) or send code to a REPL or...

Speaking as someone who doesn't use it, but understands it well, the one and only thing that excites me is the persistence of sessions, if your connection drops, you can reconnect and everything is still there. Love that idea. Everything else is solved that I know it does well (for me) by using tabs. I could very well be missing other things, I know it does quite a bit, but most of the things I see other people use it for is solved by tabs (for me at least).
This is the big thing for me. I used to work almost exclusively on a remote dev machine, using my laptop as a terminal, and tmux meant I could pick up in the morning where I left off the day before. Now, I work on a desktop, but I've gotten used to using tmux and using it locally means I can ssh to my work machine from home and, again, pick up where I left off.
Session sharing is also handy in specific cases. It supports both read only, and read/write shared sessions.

The other feature that's used often is the general scriptability that the command line options make possible. "send-keys" for example can be useful...it sends keystrokes to specific named sessions.

Doesn't mosh do that as well (or better)?
I kind of see what you mean, but tmux and mosh are completely different things and have (almost?) completely different use cases. Mosh is replacement for ssh.

Without talking about the other huge benefits of tmux, mosh only helps (and was designed to) prevent disconnections and other inconveniences when your internet connection falters. If for example your terminal unexpectedly closes you can't reconnect to your ongoing mosh session (this is an intended feature for security reasons).

Tmux on the other hand wouldn't help against a poor internet connection, but at least if your terminal or your ssh session closes you can just restart another one and wouldn't lose anything.

In other words, always use tmux, and tmux+mosh if your internet connection is poor.

mosh only supports reattaching from the originally started client - no attaching from different machines, no resuming sessions after reboots, etc. Also no splits, and no scrollback.

It's also extremely slow. Fullscreen terminals on my 30" display are borderline unusable with mosh.

Since you're using iTerm, here's a fancy little trick:

If you're connected to a remote machine, run 'tmux -CC'. Tmux tabs on the remote machine will appear as iTerm tabs on your local machine. (This works for attaching to existing tmux sessions as well: 'tmux -CC attach'.)

Interesting. The only thing I could find on the man page with CC change cursor color. How did you come upon this?
I don't believe it's actually a feature of tmux itself, but rather iTerm. My suspicion is that iTerm watches for that command in particular and rewrites it behind the scenes.

I was told about it by a coworker - more detailed info can be found here:

https://gitlab.com/gnachman/iterm2/wikis/TmuxIntegration

I much prefer tmux because it really doesn't matter what system I'm on, I can easily rearrange windows/panes and form a custom workspace. While iTerm can do this on the local mac, it's a real pain to use tabs/splits in it over SSH. Plus, like others mentioned, tmux stays alive.

I also just prefer the interface of tmux. You can completely configure your status bar as well, and I find that really useful. For example, my status bar [1] has my current music, host, time in the two timezones I care about, and load. I also use a commandline chat client for work that I can embed into a tmux pane and never have to switch away from iTerm to communicate.

[1] http://i.imgur.com/XrKtV7J.png

I use tmux and screen mostly because of their "detach" function, so I can connect to the machine over SSH and attach to existing pseudo-terminal later.
On your own machine, I don't think there is any reason (others may disagree!)

On another machine, your session remains alive even when you disconnect.

You can get the best of both worlds with iTerm, by running tmux -CC, which shows tmux's seperate tabs as iTerm tabs, which is super-cool when you are connected to a remote machine!

In addition to persisted sessions across ssh, you can also split windows horizontally and vertically, rearranging them on the fly.
There is a nice function that I think GNU Screen does not have: C-b <space>. It rearranges all the windows dynamically, similar to dwm[0] layouts.

[0] http://dwm.suckless.org