Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Other options for resumable sessions: tmux/screen + https://eternalterminal.dev/ or https://wezterm.org/ which can resume open windows like you get with iTerm2+tmux.


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.


And case in point, mosh is another terminal layer, it's also a multiplexer of sorts.

I've used mosh a lot but it's just interesting to note it's in the same category as screen and tmux


On mobile so I’m not sure which case OSC52 applies to, but I use mosh+tmux 8-10 hours a day. Both bracketed paste and tmux selection setting local clipboard work fine


it sort of does support it, except it doesn't work with tmux.


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.


Haha I think you have the history backwards here. Tmux was created as a replacement for screen when it was 20 years old! Speaking as someone with ‘set -g prefix c-a’ in their .tmux.conf because my muscle memory is so used to the screen hotkeys.

GNU screen was released in 1987.

tmux was created in 2007.


Hey maybe I do! Great to learn the history here. Regardless, my point is that Byobu is very nice compared to either. That may now be lost due to my careless comment.


It's seamless until you want to scroll.


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've had it on C-o forever to mostly stay out of readline's way, but I've been dabbling with C-Space.


I never really understood the people who use these keybinds. Do you not use it to go to the start of the line?


Ctrl-a and then a still goes to the start of the line.


Personally no, I use vim keybindings in the terminal not emacs which is the default.


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.


I use tmux to replace terminal emulator tabs, I also suspend jobs all the time (most notably vim to run git commands)

In any case with your bindings you can still C-z z and it sends C-z to the process.


I'll bite. What's so obvious? I suspend jobs in bash all the time while using tmux.


Often TMUX it's for tasks you woudn't suspend. And, if any, you can just use kill -STOP and kill -CONT among other signals from another tmux pane.


Or if you want to stay in same pane, (chord, I still use C-b), :, "send-keys C-z"


+1. Was using screen with this and now tmux for the last 15 years maybe.


pinky on caps and ring finger on z ?


I use Ctrl-Space.

    unbind-key C-b
    set -g prefix C-Space
    bind-key C-Space send-prefix
I find it a lot easier to type than either Ctrl-A or Ctrl-B.


The real superpower prefix key is ` especially if you have a british mac keyboard.


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.


Isn't the screen equivalent literally this?

  Host tmux
      HostName 1.2.3.4
      IdentityFile ~/.ssh/etc.etc.etc
      RequestTTY force
      RemoteCommand screen -dR
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?


mainly sessions, i think, and maybe scripability. sessions are groups of windows. i have one session per project or work mode. (one for email and connecting to remote machines, one for writing stuff, one for managing my hobbies, one for dev work...)


Screen has sessions. You can name them, and choose which session to resume when you reconnect.

I use tmux now because it’s supposed to be cool but secretly like gp I also wonder what the actual difference is , besides a different default leader key. Oh and killer iterm2 integration.


it's been a long time since i used screen. afaik screen had one session per process. you could switch processes by detaching from one and attaching to another. in tmux it's all one process, which allows you to create new sessions and switch them interactively and move windows from one session to another, or even have a window in more than one session. i can also see all windows from all sessions:

    (0)   - main: 6 windows
    (1)   ├─> 0: elvish-
    (2)   ├─> 1: elvish*: "[mosh] embee@foo:~"
    (3)   ├─> 2: elvish
    (4)   ├─> 3: elvish: "embee@bar:~"
    (5)   ├─> 4: elvish: "[mosh] embee@fedora:/etc"
    (6)   └─> 5: elvish
    (7)   - local: 6 windows (attached)
    (8)   ├─> 0: elvish
    (9)   ├─> 1: elvish-
    (M-a) ├─> 2: [tmux]*
    (M-b) ├─> 3: elvish
    (M-c) ├─> 4: elvish
    (M-d) └─> 5: elvish
    (M-e) - dev: 7 windows (attached)
    (M-f) ├─> 0: elvish*
    (M-g) ├─> 1: elvish-
    (M-h) ├─> 2: elvish
    (M-i) ├─> 3: elvish
    (M-j) ├─> 4: elvish


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?


I could never get italics to work correctly when in iTerm2/tmux mode. Pure tmux, yes, iTerm no tmux yes, iTerm+tmux I would get weird background colors instead of italics. It's been a while so I don't remember specifics


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.


I downloaded it to try it and it basically worked out of the box. What did you try?


Wait, how do you use it with Windows terminal? Same SSH config?


In fact, Windows Terminal has an open issue for the CC mode: https://github.com/microsoft/terminal/issues/3656


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.


I'll check it out.

Note: that Terminator I linked is a re-boot (I'll be back) so, I might give it another go as well.


I was a huge tilix fan for ages, but ran into an issue with long URLs being unclickable.


wezterm


I use happily GNU Screen. Keep it?


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


Bummer!


Then a nice addition is to save typing it each time

  alias looptmux='while true; do ssh tmux; sleep 2; done'


Better:

  autossh -M0 tmux




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: