12 ms·
Little known features of iTerm2
- saagarjha 7y agoA couple more that I use often: * imgcat: you can view images without leaving your terminal. Somehow this works even across SSH connections… * Python scripting API: basically AppleScript for iTerm except it lets you touch pretty much everything and it's not soul-crushing to write. I have mine switch between themes based on the system appearance (which changes based on the time of day).
- edge17 7y ago-bash: imgcat: command not found am I missing something?
- sankha93 7y agoGP is talking about the inline images protocol: https://www.iterm2.com/documentation-images.html https://www.iterm2.com/documentation-images.html
- bdcravens 7y agoYou probably need to download and put it in your path. https://www.iterm2.com/utilities/imgcat https://www.iterm2.com/utilities/imgcat
- saagarjha 7y ago$ curl https://www.iterm2.com/utilities/imgcat > /something/on/your/path/imgcat
- krilly 7y agoOn imgcat, those extensions to the xterm protocol[0] seem really nice. I've long thought that there needs to be a simple escape sequence for a horizontal divider that doesn't break upon resizing, they should do that next! Also check out tiv[1] which is an alternative that works with any unicode terminal. [0]: https://www.iterm2.com/documentation-images.html https://www.iterm2.com/documentation-images.html [1]:https://github.com/stefanhaustein/TerminalImageViewer https://github.com/stefanhaustein/TerminalImageViewer
- enriquto 7y agoThese iterm image extensions are almost there. It is unfortunate that it can only display files, and not image created on the fly (i.e., you dump all the pixel values into the terminal and it shows an image).
- Doxin 7y agoThe actual extension does support images created on the fly. All that's missing is some commandline tool that'll translate from whichever format it's in to the format iterm expects. For e.g. a PNG image data you could probably get away with a single-line bash script: all it has to do is stick an escape sequence in front of the base64 encoded file contents.
- enriquto 7y agothat's great! I hope it will be implemented for xterm and becomes a sort of standard. Sometimes I use "sixels" but they are hopelessly slow and low-resolution. Not much a fan of the base64 encoding here. I'd prefer if it was the pixel binary buffer data that you output directly, pinching a hole in the terminal protocol. The fact taht it is binary does not pose problems if the escape sequence contains the size of the image.
- deleted 7y ago[deleted]
- misnome 7y agoimgcat and image displaying is amazing; I use a matplotlib backend that renders plots inline in the terminal, makes remote working much nicer. Along with imgcat there’s it2dl. Downloads a file from the remote system browser-style. It’s much more convenient than scp, especially when several sessions deep.
- Sean1708 7y ago> Somehow this works even across SSH connections… The source code[1] is quite simple to read (as long as you know Bash) but basically imgcat prints a special OSC[2] sequence (some bytes that tell the terminal to do something special) to stdout followed by the image data which iTerm then handles specially because of the OSC sequence, as far as SSH knows they're just some bytes that it needs to send (no different than running normal cat on a text file). You can kind of think of this as the opposite of what bracketed paste[3] does, in bracketed paste the terminal tells the program to treat some data specially but with imgcat the program tells the terminal to treat some data specially. [1]: https://iterm2.com/utilities/imgcat https://iterm2.com/utilities/imgcat [2]: https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequences https://en.wikipedia.org/wiki/ANSI_escape_code#Escape_sequen... [3]: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Bracketed-Paste-Mode https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-B...
- kiddico 7y agoMintty/Cygwin has a similar utility[1] for images (I've not tested it over ssh. Should be the same idea though) [1] https://github.com/mintty/utils/blob/master/showimg https://github.com/mintty/utils/blob/master/showimg
- sk0g 7y agoI'm a little jealous of iTerm, not going to lie. The UX is pretty nice from what I've seen, but I can't find a like for like replacement for either Windows or Linux.
- 29athrowaway 7y agoTilix can be a decent alternative.
- sk0g 7y agoLooks great! Will install it on my Ubuntu VM, cheers :)
- yoklov 7y agoIt is something I miss a great deal when on other OSes
- bdcravens 7y agoEvery time I've considered a full-on switch to Linux, the many little tools that I'd have to give up weigh heavily the cons column.
- deleted 7y ago[deleted]
- pkrumins 7y agoWhich tools would you have to give up?
- bdcravens 7y agoSome of the most obvious things I'd give up: - ability to plug into any monitor at any resolution that monitor supports - ability to copy and paste to/from my phone - Transmit - I really haven't found many good s3 clients on Linux - ScreenFlow - Git Tower Most of these have some sort of a work-around or close analog of course. (So I'd likely not be "giving anything up" as much as compromising or learning new techniques) However, I'm not sold on the benefits (other than ideological ones, the only thing that comes to mind is increased Docker performance) outweighing the costs. For someone with a different workflow and set of tools, a different conclusion may result.
- _chendo_ 7y agoSemantic History is pretty handy and not well-known. It lets you Command+Click on a path to open it in your editor (or associated application). It also lets you Command+Drag a path to get a usable file-handle to drop into other apps that handle file-related dropzones. Demo video I made when I added the feature: https://vimeo.com/21872771 https://vimeo.com/21872771
- milkbikis 7y agoWow, thanks for creating it!
- saagarjha 7y agoUse it with care, though: it's not shy about creating invalid file references when it doesn't know what it's talking about :)
- Myrmornis 7y agoCan it extract the correct line number from tracebacks, compiler / linter output etc? I wrote this tool, but I know George Nachman has added some features since I wtote it: https://github.com/dandavison/iterm2-dwim https://github.com/dandavison/iterm2-dwim
- _chendo_ 7y agoIt should, I originally built it for rspec output but it should work with most common formats that put the line number attached to the path with a colon.
- locusofself 7y agotmux -CC support is my favorite feature of iTerm2. It's amazing.
- saagarjha 7y agoAside from that, I have no idea how to use tmux ;)
- rhlsthrm 7y agoCan anyone ELI5 on Tmux? I want to know if I’m missing out on an awesome tool by not knowing about it by having heard the name it a lot.
- stekern 7y agoIn short, it's a terminal multiplexer (hence the name, tmux) that allows you to run multiple terminals within one (as opposed to opening a new window for each interactive shell you want to use). I spend 90% of my time as a developer either inside tmux or a web browser, so it wouldn't be a stretch to say that I find it quite useful. The functionality I use the most in tmux is: - attaching and detaching from a tmux session (e.g., for running machine learning jobs over SSH) - having multiple terminals open inside of one - scripting the setup of windows, panes, etc. for different projects I'm working on I basically use vim and tmux as an IDE: my usual setup consists of one large pane consisting of vim and code, while two other panes are available for running git commands, starting servers, etc. Within one tmux session I separate different projects (e.g., frontend and backend) into tmux windows, and it's very easy to switch between panes, windows and sessions using keyboard shortcuts.
- bmn__ 7y agoIf you didn't miss it until now, it's likely you won't need in much in the future, either. Three main features and their value as I judge them: * Detach/reattach sessions. This is useful; I run a always connected IRC client on my home machine in a detached session, then reattach to it on the go or from work. Tip: http://enwp.org/Byobu_(software) http://enwp.org/Byobu_(software) / http://byobu.co http://byobu.co has a vastly better out-of-the-box experience than plain tmux. * Split screens. I never use it. My GUI terminal emulator software already can do that, but plain tabs or the window manager's features have always been sufficient. * Connection multiplexing. SSH already does that for me, see `ControlMaster` and `ControlPath` in `man 5 ssh_config`.
- snide 7y agoI was one of those vim users that was stuck on MacVim for years because my brain was too wired to hitting "cmd-s" for save and other dedicated app niceties. I mean, sure I can :w or bind it to another key, but there are a couple shared OS-level shortcuts like this I just like to retain. No worry, iTerm2 can capture ANYTHING, and rebind it as needed. This means I have a few remaps like "cmd-s" in iterm2 to map to obscure key combinations, which I then have vim interpret and pass along to whatever I want to bind over there. I had no idea the feature existed for years. And sure, I know you're all laughing, why would I even do such a thing... but vim is vim, and we all have our own weird version of it. iTerm2 is amazing. I've been using it for years daily and it is 100% one of the best, most reliable pieces of software in my toolkit, right next to Alfred. Show you love for George and contribute to his Patreon[0]. We always love to complain about how to make money with open source on HN. I'd love to see him making a lot more than he does, if for no other reason than we can get more people working full time on the project and provide some redundancy for a critical tool we all love. I wish I could pay for it, but I guess Patreon works. [0]: https://www.patreon.com/gnachman https://www.patreon.com/gnachman
- AlchemistCamp 7y agoReally? I didn't think iTerm would pass along cmd keys, which is the primary reason I use MacVim instead. For example, I use these kinds of mappings: nmap <D-j> <C-j> nmap <D-k> <C-k> nmap <D-h> <C-h> nmap <D-l> <C-l> nmap <C-[> <C-T> nmap <D-]> <C-]> nmap <D-[> <C-]> nmap <D-p> :CtrlP pwd<cr> nmap <D-r> :CtrlPBufTag<cr> nmap <D-e> :CtrlPMRUFiles<cr> This way, when on a Mac I can use cmd in place of ctrl for various commands I use all the time that are less convenient with ctrl. In my .gvimrc, I added the following to make sure that cmd-p and cmd-l don't get incercepted: "Disable the print key for MacVim" if has("gui_macvim") macmenu &File.Print key=<nop> macmenu &Tools.List\ Errors key=<nop> "macmenu &MacVim.Hide\ MacVim key=<nop> set macligatures endif If there's any possible way to accomplish the same with iTerm, I'd give it another try!
- Myrmornis 7y agoNot a vim user but iTerm2 settings have a section for rebinding modifier keys, (plus you also have karabiner-elements)
- aloer 7y agoI’ve said it before: iterm2 is one of the two reasons I feel so much more productive on mac compared to Windows or Ubuntu The other one being quicklook (space preview of files)
- giancarlostoro 7y agoI installed it on Mac to attempt to come close to using Tilix on Ubuntu but I think I prefer Tilix overall. It comes default with Ubuntu Budgie. Tilix isnt perfect and has its weirdness but its really awesome to use.
- jfkebwjsbx 7y agoWeird thing to say, considering both Windows and Linux-based systems are way more developer-friendly. (Windows due to VS and the rest of MS resources/docs/tools, Linux due to its package management systems natively supporting just about anything you could ever need for development. For macOS to compete, you need a plethora of best-effort or paid tools that don’t come from Apple).
- atom-morgan 7y agoWhat's your iTerm2 replacement on Windows? I use Hyper right now but the clear command doesn't even work correctly.
- garethrowlands 7y agoHave you given Windows Terminal a try? It's in the store. https://github.com/microsoft/terminal https://github.com/microsoft/terminal
- hacym 7y agoAlso a weird thing to say. VS is on Mac, and not everyone uses VS to develop. Mac also has brew, which is a great package manager that can replace apt and the like. Sounds like you have a specific use case that requires you to use Windows and are projecting that on every other use case. There is a reason why Macs are used in a lot of development shops.
- yen223 7y agoI've found a lot of use from cmd-shift-e, which shows timestamps for each output line in the terminal. Great for figuring out how long a process ran for.
- klysm 7y agoI usually have my PS1 show how long the previous command took
- yen223 7y agoThe cool thing about iterm's timestamp is that it even applies to SSH and other shells
- dharmab 7y agoI've also used this for building outage timelines after the fact by noting the timestamps for my first time to touch and the timestamp of the repair.
- ke2g 7y agodidn't know this, amazing :O
- chaos_a 7y agoIs there a way to make the timestamps permanent? Kinda sucks that they disappear when you close iTerm.
- kristofferR 7y agoNot natively: https://gitlab.com/gnachman/iterm2/issues/4492 https://gitlab.com/gnachman/iterm2/issues/4492 However, you could probably hack together a fix pretty easily with this: https://github.com/BlueM/cliclick https://github.com/BlueM/cliclick Make it press cmd-shift-e as a Profile command.
- paxswill 7y agoWould having them print directly in the shell prompt work? For bash, I combine PS0 support (in bash >=4.4) and PROMPT_COMMAND to do this. My prompt command: https://github.com/paxswill/dotfiles/blob/c4c6d50123fc2535e23cb75e6da576d46f93ca4b/util/apps.sh https://github.com/paxswill/dotfiles/blob/c4c6d50123fc2535e2... And PS0: https://github.com/paxswill/dotfiles/blob/c4c6d50123fc2535e23cb75e6da576d46f93ca4b/util/apps.sh https://github.com/paxswill/dotfiles/blob/c4c6d50123fc2535e2... Basically the prompt command writes the current time stamp on the right edge of the window whenever the prompt is printed. Then PS0 overwrites that time stamp right before a command is executed. If you want the time stamp on the left you can skip the prompt command and tput usage by using the \t escape code in PS1, but PS0 will need to be modified for the new location while still using tput.
- babayega2 7y agoQuestion. Do you know how to get iTerm2 to open on split into the same directory that it was in like in Terminator on Ubuntu? Currently it always open to home directory whether I do a vertical/horizontal split.
- kevsim 7y agoGo to Preferences->Profiles->Default and find the option over on the right for "Working Directory". Then set it to "Reuse previous session's directory". Then for me Cmd+D and Cmd+Shift+D (split with current profile) gives the same current directory.
- sorahn 7y agoDepending on your workflow, you might even want the advanced configuration version of this. I want new windows (which I rarely use) and new tabs to be my home directory, but split panes to be the directory I was in when I split. Works wonders.
- sbr464 7y agoLike @kevsim mentioned, you have to go advanced options etc, it’s hidden a bit, but it’s there.
- nrclark 7y agoNot 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
- Cthulhu_ 7y agoRemove the `-F` flag right in front of that, works for me after that.
- guessmyname 7y agoiTerm2 has so many features [1] I don’t think I have enough space here to promote them all. Please consider setting up recurrent donations to George Nachman [2] to support his work. [1] https://www.iterm2.com/documentation-one-page.html https://www.iterm2.com/documentation-one-page.html [2] https://www.iterm2.com/donate.html https://www.iterm2.com/donate.html
- raamdev 7y agoI’m surprised to see that the iTerm2 dedicated hotkey window hasn’t been mentioned. It’s essentially a system-wide terminal window that you can open with a hotkey, similar to the old Visor app, and you can configure it as a floating window that appears over other apps' full screen windows. https://www.iterm2.com/documentation-hotkey.html https://www.iterm2.com/documentation-hotkey.html
- jaaames 7y agoYeah - I use this workflow and love it. cmd + esp (with caps lock remapped to escape) to toggle a full screen terminal from any application. Means don't have to cmd + tab and hunt for it, it's always one shortcut away.
- Myrmornis 7y agoAgreed this is the most important feature for me. I use it in the same way.
- amrox 7y agoI just discovered this last night! Such a cool feature.
- ascagnel_ 7y agoI always loved that feature -- you can map it to tilde (~) and set it to a full-width, top-docked window to emulate an old Quake-style terminal.
- donatj 7y agoThis feels like a dumb question, but is the text rendering really dark for others in iTerm2? It seems like on a black background I cannot get pure white text. It’s always a middle shade of gray for me - before and after getting a Retina display. I have messed with the colors and text rendering for literal hours over the last ten years and I genuinely cannot get it as clear and readable as Terminal.app which is a big part of the reason I always end up falling back to Terminal
- cerberusss 7y agoiTerm -> Preferences -> Profiles tab -> Colors subtab. You'll see two columns of options. The left column is titled "Basic Colors", the right is titled "ANSI Colors". Under Basic Colors, click the color next to Foreground, and a color picker appears. Slide it to the lower-left: bright white. Now it should be fixed. But if it didn't, repeat the same procedure for the White that's at the bottom of the column ANSI Colors.
- TurkTurkleton 7y agoThere's also a setting that controls the thickness of font strokes, independent of color. I forget exactly how it's labeled (not at my Mac right now), but I remember it's a dropdown with combinations of options for using thin strokes on dark backgrounds and/or Retina displays. I believe it defaults to using thin strokes on Retina displays. I believe turning this off will make font rendering identical to Terminal. Either way, I think it looks better turned off, even on a Retina display.
- dzhiurgis 7y agoI love iTerm! I've wondered whether it's possible to setup profile-specific (or folder-specific) aliases? I understand it might be zsh feature that I'm really after, but perhaps iTerm can solve it too?
- Cthulhu_ 7y agoI think you'll have to look into some scripting then; what you could do is create your aliases for each profile in a separate folder, then use the 'Send text at start' profile to just do a `source ~/profiles/1/aliases.sh` or something to that effect.
- eddyg 7y agoProfile-specific aliases are easy. In your .zshrc (or .bashrc), just use the value of $ITERM_PROFILE to set (or source a file containing) the aliases you want: [[ $ITERM_PROFILE == “AWS” ]] && source ~/.aliases.aws
- Myrmornis 7y agoA little plug: iterm2-dwim is a click handler that makes use of the iTerm2 smart selection feature to open files in your editor at the correct line. https://github.com/dandavison/iterm2-dwim https://github.com/dandavison/iterm2-dwim From the README: iterm2-dwim is a click handler for iTerm2. The aim is that you command-click on any file path, relative or absolute, and it opens the file in your editor. If there was a line number, your editor goes to that line. So, compiler/linter output, tracebacks, git output, etc. Currently Emacs, PyCharm and Sublime are supported.
- bad_user 7y agoiTerm2 is what made me finally use Emacs in the terminal, completely replacing vim for me. You can configure Emacs when running from the terminal to respond to mouse input or to integrate with the system's clipboard. You make it run in server mode, via a Launchd config and you get instant startup times too. iTerm2 also has built-in powerline glyphs. It was actually easier to configure Emacs's powerline package to work from the terminal than it was to work from the GUI version. I also like iTerm2's tmux integration. iTerm2 is one of the reasons why I won't abandon MacOS for my software development needs anytime soon.
- allarm 7y agoWhy using Emacs in terminal though? I find it much better to run in gui.
- shabbyrobe 7y agoiTerm2 is fantastic! It can be a bit CPU hungry but you get a stack of mod cons out of the bargain. There are tons of proprietary escape codes, not least of all the incredibly useful one for "fireworks"! [1] ^[]1337;RequestAttention=fireworks^G [1]: https://iterm2.com/documentation-escape-codes.html https://iterm2.com/documentation-escape-codes.html
- peteretep 7y agoTo save people needing to lookup how to use that: perl -e 'print "\e]1337;RequestAttention=fireworks\007\n"'
- MockObject 7y agoand echo -e "\x1B]1337;RequestAttention=fireworks\007"
- freakcage 7y agoCool article, but here I am don't know how to jump between words on iterm2
- mikeappell 7y agoYou can set this up as a shortcut. I forget exactly how I did it, but here's what seems to be a similar guide on macos: https://coderwall.com/p/h6yfda/use-and-to-jump-forwards-backwards-words-in-iterm-2-on-os-x https://coderwall.com/p/h6yfda/use-and-to-jump-forwards-back...
- acidictadpole 7y agoSomething that I do: `set -o vi` and then hit `<ESC>`. You now have vim motion-like controls to navigate on the command line: - `b` goes back a word. - `w` goes forward a word. - `0` goes to the beginning of the line. - `$` goes to the end of the line. etc. I put `set -o vi` in my rc file so I have it on by default.
- cs02rm0 7y agoAnyone else have any problems getting the first one to work? I could run /usr/local/bin/hub browse -- commit abc123 without issue, but iTerm wasn't even changing to cursor when hovering over a hash and holding cmd.
- cs02rm0 7y agoNevermind. Think quitting iTerm was key. Off/on again.
- Corrado 7y agoI love iTerm2 and have been using it for years. Thanks to this post I've even learned a couple of new things that make me love it even more. One thing I've been trying to get working in iTerm2 has been AWS profile badges. iTerm2 has the ability to use text "badges"[0] to give feedback about the current environment. I'm an AWS engineer and tend to switch between environments a lot, so I thought it would be great to use the badges functionality to let me know when I was in the production environment vs. say, the development environment. This seems pretty simple but I haven't been able to get it to work. [0] https://iterm2.com/documentation-badges.html https://iterm2.com/documentation-badges.html
- MockObject 7y agoHow does your shell know which environment you're in? Is it that you ssh into one environment or another one, and you want the badge to show which one you've connected to?
- Corrado 7y agoI cut and paste environment variables into the shell to authenticate to different accounts. Originally, I was trying to trigger an event by looking for specific words (ie. AWS_SECRET_ID) but that didn't seem to work reliably.
- MockObject 7y agoIf you're switching between envs with cut and paste, maybe you could do likewise with the badge? echo -e "\x1B]1337;SetBadgeFormat=$(echo "production" | base64)\007" echo -e "\x1B]1337;SetBadgeFormat=$(echo "development" | base64)\007" Consider giving yourself some bash functions with appropriate names, which set the env vars and switch the badge too. Then instead of pasting each time, you'll just use the function name in the shell. https://linuxize.com/post/bash-functions/ https://linuxize.com/post/bash-functions/
- andreareina 7y agoiTerm2 has (had? I stopped using it a while ago) the tendency to drop data from a large paste. No problems with the built-in Terminal.app so I just went back to that.
- mark_l_watson 7y agoFor me, the killer feature is supporting inline plots in a shell, in a terminal-based Emacs session, etc. I have a short section in my latest book on setting it up, which you can read free online: https://leanpub.com/hy-lisp-python/read#leanpub-auto-bonus-points-configuration-for-macos-and-iterm2-for-generating-plots-inline-in-a-hy-repl-and-shell https://leanpub.com/hy-lisp-python/read#leanpub-auto-bonus-p...
- ashton314 7y agoiTerm2 is going to be the killer app that keeps me on macOS for a long time. Is there anything remotely as good for Linux systems?
- gnachman 7y agoHi, author here. What a great way to wake up, an HN love fest :) Check our the Tip of the Day feature, which is meant to help you find stuff like this.
- jhallenworld 7y agoAny chance of a port to Linux/X (Ubuntu) and especially Windows? I recently needed a terminal emulator that supports Sixel.
- acidictadpole 7y agoSecond this. ITerm2 is the only console emulator that I actually enjoy using. I've been flip-flopping on terminals on windows and linux constantly.
- gnachman 7y agoIt’s a simple matter of funding me for the next 7 years :)
- jhallenworld 7y agoI suspect it's a simple matter of giving you a job where you are forced to use Windows for everything :)
- yeswecatan 7y agoThe github trick is pretty cool. I'm running into an issue though where it opens the link but in the wrong repo. Have you ever experienced that?
- wincy 7y agoI thought I was being fancy when I figured out I could use CMD+shift+c to get vim-style visual selection to yank some terminal output in a pinch.