Comment by jelder
1 day ago
This is written for the Linux-on-the-Desktop crowd, and good for them. But tmux really shines for folks using MacBooks with iTerm2. Its tmux integration is so good that it simply disappears into my workflow.
With this in my `~/.ssh/config`, I can just type `ssh tmux` to get back to my remote dev box whenever I wake my computer or change connections.
Host tmux
HostName 1.2.3.4
IdentityFile ~/.ssh/etc.etc.etc
RequestTTY force
RemoteCommand tmux -CC new -A -s 0
With iTerm2's tmux integration enabled, this will pop open a new window where the remote tmux tabs and scroll buffer look and act just like native, local iTerm2 tabs and scroll buffer. I don't even know any tmux commands.
As someone who uses Linux on all my personal machines but has usually had to use a MacBook for work, tmux is also pretty useful as a platform- independent tool for me to reuse the same workflow without needing to worry about differences between the two. I use Alacritty on Linux, but when I've tried using it on MacOS, there have things that don't seem to work for me out of the box the same way they do in Linux (which I'm struggling to remember exactly at the moment, but I think one of them might have been the setting to have the window maximized on startup). Rather than spend time trying to tinker around on an operating system that I don't have any particular desire to use outside of just getting my work done, it's pretty nice to be able to use tmux on iTerm to get basically the same experience I do on Linux. From that perspective, having something like an entirely independent way of scrolling back in a session is a feature to me, not an annoyance.
A lot of these arguments against tmux seem like they're more relevant to someone developing a terminal rather than using it. It's fine for people working on their own terminals to decide they don't care to support it, but I don't really find the arguments convincing as something I should care about, and I'd personally just switch to another terminal with better support for it rather than stop using it.
I use a combination of mosh and screen for this. I only need to type something to get my session back, after a reboot. Changing networks or putting my laptop to sleep for days doesn't drop my sessions: https://www.grepular.com/Immortal_SSH_Sessions
Mosh is incredibly useful. I have sessions running from uptime until reboot with machines (pis and a desktop) on my local network from my laptop.
I leave with the laptop, return days later, and perform no manual intervention to reconnect. It's absolutely brilliant.
I used mosh when my data plan plumetted to 2.7 KBPS (~ISDN/2G speeds).
I connected to a public Unix server and read news, IRC'ed, IM'ed and such like crazy. Also, without being connected to a Pubnix, IRC and Gopher did it fine, the web with patience, and the same with Gemini (gemini://gemi.dev has been really useful to read news and scrap a 95% of unneeded scripts and trackers from web sites).
Usenet was slow on fetching, but totally readable the next morning, and, better, offline.
Mosh looks very cool, though I've never used it. Does Screen provide some advantage over tmux in this setup?
Mosh is excellent. It lets remote sessions survive (well, automatically and transparently recover from) disruption that reliably kills ssh.
I basically don't use ssh at all any more for interactive sessions, because I'm sick of a few lost packets on wifi or a weak cell signal dropping my connections and forcing me to start over.
Tmux, I used to use and eventually abandoned. I decided I didn't need two keyboard-based window managers (I use Spectacle on Mac) and the one that was only for shells was the one that could go. I have replaced it with nothing, so far, aside from that I just open more Terminal.app windows now (I also used to use iTerm2, for years, until it dawned on me that I was using exactly nothing in it that's not also provided by Terminal.app, and the latter's got better input latency, so I was suffering an extra installed program and slightly less responsive typing for no reason at all)
Mosh does not support OSC52, so it's a barrier to getting copy/paste to work.
3 replies →
Yes. Mosh is a seamless replacement for ssh, and screen is a mostly seamless replacement for tmux. One more level is Mosh+byobu, which is so useful I don't even bother with plain terminals most the time.
3 replies →
Wow, I've tried tmux like a hundred times and could never learn to like it, falling back to screen and promising to myself - never again. I'm going to break my promise to try this.
I've always found screen's ctrl-a is so much easier to reach for than tmux's ctrl-b. I recommend re-mapping ctrl-b to ctrl-a
I never really understood the people who use these keybinds. Do you not use it to go to the start of the line?
2 replies →
I've had it on C-o forever to mostly stay out of readline's way, but I've been dabbling with C-Space.
I use Ctrl-Space.
I find it a lot easier to type than either Ctrl-A or Ctrl-B.
1 reply →
Both C-a and C-b are so commonly used that I don’t like either of them. I ended up going with C-\ since I only rarely use that one.
I just remapped the keys to ctrl-z after I swapped ctrl and caps lock. As you'd never suspend stuff under tmux for obvious reasons, you'll get the whole keyset for any cli/tui software.
4 replies →
Isn't the screen equivalent literally this?
Edit: I guess it's missing the iTerm integration
> falling back to screen
So you're saying you're a masochist
I’ve used screen for 25 years. What am I missing without tmux?
I ran into so many little annoying color and font issues with vim, tmux and iTerm2 that I gave up on tmux (for local work). What small benefit I got from tmux on my local machine (basically surviving updates and a little more session persistence) I rarely miss.
I wanted it to be better, and might go back if I could figure out the font issues, but I just don't have the time right now.
> vim, tmux and iTerm2
Interesting, I've been using exactly that combination for ... as long as tmux and iTerm2 have been around?
I am not aware of any color or font issues. What am I missing?
Does any Linux terminal have a comparable integration? I'm still using GNU Screen but willing to give tmux another shot.
WezTerm
The author of this feature also ported it to the Windows Terminal.
Besides, Chrome OS’s built in terminal also has tmux integration.
Do you have links to any examples? I've searched for this on and off for years, and i use Wezterm, but i've never been able to make it work like i remember the iTerm2 integration working.
Would love for examples using Windows Terminal as well.
1 reply →
There was one called Terminator which had some tmux like features, split panes, broadcast, etc. It's not been maintained in a bit.
https://gnome-terminator.org/
I used to use terminator for a long time, but i've switched to tilix (https://gnunn1.github.io/tilix-web/) with little pain.
1 reply →
I use happily GNU Screen. Keep it?
wezterm
Pretty sure iTerm is the only term that implements that tmux protocol.
ITerm2 seems really cool, it has so many features. The developer(s?) must be really productive, they churn it out. They support a lot of Kitty protocols for example.
Ghostty has infrastructure to support it from my understanding, like Mitchell did the initial plumbing. It just takes a spirited individual to finish it up.
I've just now learned about tmux's control mode. Can you explain what that tmux -CC command does? I use `ssh -t <host> tmux attach -d` from bash history to (re)establish my remote tmux session. `new -A -s 0` would do the about same thing, I just don't see how -CC is supposed to work here.
Edit: It appears to be related to iterm2's tmux integration. Neat.
You might not need control mode for that, try `autossh foo ‘tmux new-session -A’`
Wow, I was wondering if e.g. Ghostty could implement something like this but that's cool it's already proven out.
Does everything still go "through" tmux (so parsing etc. is still done twice), or does iTerm handle most of the rendering and just delegate scrollback storage/session persistence to tmux? The latter seems like the best of both worlds.
Composing simpler tools works better than complicated tools that try to solve everything.
I am a former Kitty user and current Ghostty user and hope Ghostty stays basic and good.
Would mosh stop you from having to reconnect to SSH at least after wake? You'd still need to reestablish a mosh connection after rebooting.
Tmux cc mode doesn't work over mosh. Something to do with how it mangles binary going over the wire. Breaks other iTerm2 features like local copy paste from remote paste boards, drag and drop uploaf and download
Then a nice addition is to save typing it each time
Better: