6 ms·
Not sure whether or not this is a little-known feature. iTerm2 has _fantastic_ integration with tmux (software used for persisting a terminal session across mul
by nrclark 7y ago
Not sure whether or not this is a little-known feature. iTerm2 has _fantastic_ integration with tmux (software used for persisting a terminal session across multiple logins).
Tmux can be a pretty complex piece of software, but iTerm can basically wrap it all up into a nice package. You don't need to know anything at all about tmux to use iTerm's tmux integration.
If you're SSHed into a server that has tmux installed, try running `tmux -CC` on the server. It'll pop up a new window that looks and feels just like it's running natively (complete with tab support), except it's all tunneled over SSH.
And if you disconnect, you can just reconnect later and your windows will all come back in the same state as when you left them.
I use this one-liner to SSH into a server and reconnect (or start) a tmux session:
ssh -XY -F user@hostname -Ct \
'sh -l -c "exec tmux -CC -u new-session -AD -s remote"'
iTerm2's tmux integration makes SSH access to remote machines feel almost as native as using your machine locally. It's really a killer feature, and it made iTerm2 worth a donation for me.
- kpozin 7y agoI really wish some Linux-based terminal emulator would copy this feature.
- mdtusz 7y agoI'm not too sure if it has this built-in by default, but I've found kitty terminal to be the nearest thing to iterm for Linux. Lots of customizability and it has fairly good docs which is always a plus.
- mobilemidget 7y agoafter years of seeing tmux fly by, and still not understanding its purpose I thought okay, lets give this one liner a try and see if I really don't need to know about tmux as you wrote. :) why do I get: Can't open user config file <user@host-redacted>: No such file or directory
- jsmeaton 7y agoI haven’t really figured out Tmux, and I’m a little ashamed to admit it. I usually reach for screen when needed, and disconnect/reconnect/kill are the only commands of screen I know. I’ll give the tmux -CC a go when I’m back at my machine, but what else does the integration do? I’m a heavy pane user - does the default split pane in tmux mode use tmux splitting for example?
- reubenmorais 7y agoYes, splitting panes in iTerm will crate tmux panes on the remote. It's a pretty neat feature.
- Myrmornis 7y agoI mean, it uses it, but it no longer feels like tmux, and you don’t have nice tmux features like zoom-pane, right? iTerm2 is absolutely fantastic and I would miss it if I moved to a linux laptop, but I still haven’t seen the attraction of the tmux integration yet!
- oblio 7y agoiTerm2 panes can be zoomed in.
- jsmeaton 7y agoAs in maximise to take up the entire window? cmd+shift+enter to toggle, I love this feature.
- nrclark 7y agoVery true that you don't really have access to zoom-pane type features. But they're also not really applicable. The integration is more about giving you a native "tabs and GUI windows" kind of feel, so that you can have multiple terminals open without needing to mess around with panes, tmux windows, etc. And of course, that gets provided in a persistent way (so that you can disconnect and reconnect at will) just like a normal tmux experience.
- rawfan 7y agoSo what exactly is the iTerm feature here? You are just describing regular tmux.
- neilsense 7y agoit pulls out windows into terminal tabs (in the UI), and handles panes like they were native iTerm panes (so same keybindings etc). Makes for a native-feeling experience while still getting the benefits of tmux.
- nrclark 7y agoiTerm2 will use tmux's scripting mode to give you a "tmux without tmux" kind of experience. Scrollback will work normally, and so will opening new terminal tabs and new windows. It doesn't give you anything if you're already comfortable with tmux. But if you want your experience to "feel" more native, it's an awesome tool.
- mosselman 7y agoSo when Volkswagen releases a new car you say "what is new here? You are just describing regular Cugnot's steam wagon?"
- Myrmornis 7y agoI use iTerm2 with tmux every day (but I don’t ssh into machines often nowadays) and I feel oppositely — I don’t get the attraction of the tmux integration. But maybe I still haven’t understood it, so please feel free to tell me what I’m missing. For me, the purpose of using tmux on my laptop is session, window, and pane management. (Perhaps my favorite tmux feature is zoom-pane.) So I find that the iTerm2 tmux integration takes away everything I liked about tmux, and makes using tmux feel like using iTerm2 without tmux!
- mercer 7y agoI don't use tmux locally, but I find iTerm2+Tmux invaluable when it comes to managing my servers. for each of them I have an ssh command that automatically opens all the windows and panes for that particular server. It even persists colors I give various panes so I don't accidentally work in the wrong one. Saves a bunch of time!
- CJefferson 7y agoI love tmux just for letting me run long running sessions on remote machines. I don't like tmux's window management, I want to use my terminal, scroll back with mouse, that kind of thing. Tmux integration is therefore for those of us who love their GUI terminal :)
- nobleach 7y agoYou can always `set -g mouse on` in your `tmux.conf`. But that has the nasty downside of stopping you from being able to right-click and copy text to your OS clipboard. It does let you pane select and scroll with a mouse though.
- rovr138 7y agoFor someone that doesn't like or understand working with tmux windows and panes, it brings the benefit of running sessions in remote servers, being able to disconnect while still using their GUI.
- sxv 7y agoOut of curiosity, why do you use iTerm2? As a heavy tmux user, I made the switch back to Terminal recently and never looked back.
- cassianoleal 7y agoI have a function that I've aliased `ssh` to that does a similar thing, so my default is to have tmux running on the remote. It checks if the remote has tmux first though: function ssht() { /usr/bin/ssh -t "$@" "which tmux 2>&1 > /dev/null && tmux -u -CC new -A -s default" } alias ssh=ssht
- grahamperich 7y agogreat tip thanks for sharing
- nrclark 7y agoCorrection for those playing along at home: remove the -F from above. That was a cut/paste error on my part. Corrected version should be: ssh user@hostname -Ct 'sh -l -c "exec tmux -CC -u new-session -AD -s remote"'
- thegagne 7y agoMore of a normal tmux question, but is there a way to input the window number, or is there a fast way to open up ssh to 4 servers numbered sequentially? pane 1: ssh <server>-1 pane 2: ssh <server>-2 pane 3: ssh <server>-3 pane 4: ssh <server>-4
- emj 7y agoWhen I need to do cluster ssh with tmux I do this or a variant of it: function cluster_ssh() { # Start a pane for every server for server in $*; do tmux split-window ssh $server done; # Same input to all panes tmux setw synchronize-panes on; # Init pane to background, tile layout tmux break-pane -s 0 -d tmux select-layout tiled } bash# cluster_ssh server-{01..10}.example.com EDIT: made it a bit more complete, but you only need split and sync panes IMHO.
- uvatbc 7y agoI like tmuxp: https://github.com/tmux-python/tmuxp/blob/master/README.rst https://github.com/tmux-python/tmuxp/blob/master/README.rst