News for hackers. Stuff that matters.
Re:Little known features of iTerm2 by nrclark on Monday March 02, 2020 @01:46AM (#22462229)
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.
Re:Little known features of iTerm2 by jsmeaton on Monday March 02, 2020 @04:06AM (#22462836)
I 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?

Re:Little known features of iTerm2 by reubenmorais on Monday March 02, 2020 @05:12AM (#22463120)
Yes, splitting panes in iTerm will crate tmux panes on the remote. It's a pretty neat feature.
Re:Little known features of iTerm2 by Myrmornis on Monday March 02, 2020 @06:24AM (#22463480)
I 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!
Re:Little known features of iTerm2 by nrclark on Monday March 02, 2020 @02:38PM (#22468006)
Very 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.
Re:Little known features of iTerm2 by oblio on Monday March 02, 2020 @08:30AM (#22464192)
iTerm2 panes can be zoomed in.
Re:Little known features of iTerm2 by jsmeaton on Monday March 02, 2020 @02:56PM (#22468249)
As in maximise to take up the entire window? cmd+shift+enter to toggle, I love this feature.
Re:Little known features of iTerm2 by mercer on Monday March 02, 2020 @06:51AM (#22463617)
Even better, it also maintains multiple windows!
Re:Little known features of iTerm2 by Myrmornis on Monday March 02, 2020 @06:20AM (#22463455)
I 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!
Re:Little known features of iTerm2 by CJefferson on Monday March 02, 2020 @06:55AM (#22463644)
I 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 :)
Re:Little known features of iTerm2 by nobleach on Monday March 02, 2020 @11:51AM (#22466099)
You 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.
Re:Little known features of iTerm2 by rovr138 on Monday March 02, 2020 @08:15AM (#22464081)
For 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.
Re:Little known features of iTerm2 by sxv on Monday March 02, 2020 @11:32AM (#22465860)
Out of curiosity, why do you use iTerm2? As a heavy tmux user, I made the switch back to Terminal recently and never looked back.
Re:Little known features of iTerm2 by Myrmornis on Monday March 02, 2020 @06:37PM (#22470304)
- visor mode: I always have a fullscreen terminal one keypress away

- genuine fullscreen mode, not the crazy Apple thing where you try to fullscreen an app and it creates another "workspace" or "desktop" or something and you can no longer switch efficiently between fullscreened and non-fullscreened apps without seeing some sliding animation.

- Powerful keybinding support for simple and sophisticated cases. E.g. I use the "send raw bytes" feature so that I can switch panes in tmux with a single keypress, without needing to explicitly send the tmux prefix key. And all that sort of configuration can be version controlled in JSON (you certainly wouldn't want to get something like that working and then commit it to an app config dialog for safe keeping)

- settings for everything

- "dynamic profiles" You can version control your config as JSON

- configurable click behavior ("smart selection"). See other subthreads in this discussion.

- color themes and convenient color switching

Probably others.

With respect, I believe you're making a mistake. Check out some of the things I mentioned. (What does Terminal.app give you over iTerm2?)

Re:Little known features of iTerm2 by jimsmart on Monday March 02, 2020 @07:40PM (#22470706)
> visor mode: I always have a fullscreen terminal one keypress away

Last time I tried this (which, admittedly was sometime back), I found that this was ugly as heck if one has multiple screens and them set to be above one another-ish (e.g. on laptop with desktop screen(s) offset above) - it turns out that iTerm was just sliding the window in from 'offscreen', which if one has windows as I do, means it appears on an upper window.

It's slick if your screens are in 'acceptable' positions for iTerm - otherwise it's an ugly mess. Which is a shame, because I quite like / want this feature.

(Not that Terminal offers this at all mind)

Re:Little known features of iTerm2 by Myrmornis on Monday March 02, 2020 @07:44PM (#22470731)
(Replying to sibling due to HN constraints)

@jimsmart Yes I can believe that might take a bit of tweaking to get right. The author (George Nachman) is very responsive though, so I'm sure he'd appreciate the report. It might be reported/fixed/discussed already?

https://gitlab.com/gnachman/iterm2/issues/8536

Re:Little known features of iTerm2 by sxv on Saturday March 07, 2020 @12:06AM (#22509853)
> What does Terminal.app give you over iTerm2?

Ease. I've been down many a custom-config-rabbit-hole but these days I find greater pleasure in paths of least resistance. I'll admit, however, that I love my hyper key and BetterTouchTool gestures.

Re:Little known features of iTerm2 by mercer on Monday March 02, 2020 @06:53AM (#22463630)
I 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!

Re:Little known features of iTerm2 by cassianoleal on Monday March 02, 2020 @09:06AM (#22464510)
I 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
Re:Little known features of iTerm2 by kpozin on Monday March 02, 2020 @02:19AM (#22462370)
I really wish some Linux-based terminal emulator would copy this feature.
Re:Little known features of iTerm2 by mdtusz on Monday March 02, 2020 @08:08AM (#22464022)
I'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.
Re:Little known features of iTerm2 by mobilemidget on Monday March 02, 2020 @04:06AM (#22462834)
after 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

Re:Little known features of iTerm2 by nrclark on Monday March 02, 2020 @10:26AM (#22465142)
Sorry about that! Take off the -F.

I grabbed it out of a bigger script that also generates and uses an SSH config file. Looks like I pulled out the actual file from args, but not the -F.

Re:Little known features of iTerm2 by Cthulhu_ on Monday March 02, 2020 @04:57AM (#22463051)
Remove the `-F` flag right in front of that, works for me after that.
Re:Little known features of iTerm2 by nrclark on Monday March 02, 2020 @10:31AM (#22465183)
Correction 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"'
Re:Little known features of iTerm2 by thegagne on Monday March 02, 2020 @02:27PM (#22467868)
More 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

Re:Little known features of iTerm2 by emj on Monday March 02, 2020 @03:02PM (#22468308)
When 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.
Re:Little known features of iTerm2 by uvatbc on Wednesday March 04, 2020 @05:23AM (#22482599)
Re:Little known features of iTerm2 by rawfan on Monday March 02, 2020 @04:28AM (#22462926)
So what exactly is the iTerm feature here? You are just describing regular tmux.
Re:Little known features of iTerm2 by neilsense on Monday March 02, 2020 @04:35AM (#22462960)
it 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.
Re:Little known features of iTerm2 by mosselman on Monday March 02, 2020 @10:42AM (#22465288)
So when Volkswagen releases a new car you say "what is new here? You are just describing regular Cugnot's steam wagon?"
Re:Little known features of iTerm2 by nrclark on Monday March 02, 2020 @10:28AM (#22465166)
iTerm2 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.

Re:Little known features of iTerm2 by grahamperich on Monday March 02, 2020 @09:15AM (#22464587)
great tip thanks for sharing