One of the lesser known features in iTerm2 is that when you hold the command (⌘) key on your keyboard and click on a filename or a path, it tries to open it.
This can be enabled or disabled in iTerm2 Preferences.
This was working fine for me with Sublime editor until I decided to try out Atom. After switching to Atom, my iTerm2 kept opening files in Sublime, so I kind of forgot about this feature. After some annoyance, I decided to resurrect this workflow, because it is especially useful when used in combination with
rspec to open failing specs.
The two changes you need to make for this to work are kind of hidden.
1. Atom Shell Commands
First, you need to install Atom Shell Commands by going to the
Atom menu →
Install Shell Commands. This will install the commands that will allow you to launch Atom from a command line.
2. Configure iTerm2
The ⌘-click behavior is configured per profile.
- Open your iTerm2 settings page and click on the
- Select the profile you want to edit and open the
Run command...from the dropdown in the
/usr/local/bin/atom \1:\2in the text field.
You can customize the behavior by passing different options to this command. For example, if you want to always open your file in a new window, you can pass
-n like so:
/usr/local/bin/atom -n \1:\2
iTerm2 ⌘-click parameters
\2for line number
\3for text before click
\4for text after click
Atom CLI parameters
atom -h in your terminal to get these options.