31

I have output in my iTerm that is like:

  File project/path/path/file.py:56:54 extra text information

How can I open this file in IntelliJ with a single click?

Eric Bloch
  • 2,882
  • 2
  • 20
  • 26
Raúl Martín
  • 4,471
  • 3
  • 23
  • 42
  • I wonder if there's an AppleScript solution to this. Running the JetBrains binary fires up a JVM, so there's quite a delay – Graeme P Nov 29 '18 at 11:11

6 Answers6

43

IntelliJ has a command line features that you can check out here:

https://www.jetbrains.com/help/idea/2016.2/working-with-intellij-idea-features-from-command-line.html

iTerm as well enable launch a command line order when we use cmd and click over a file path pattern.

You only have to go to iTerm Preferences, Profiles, Advanced, Semantic History

iTerm configuration

In Semantic History check "Run Comand.." and add as a command:

/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea  \1 --line \2

IntelliJ has to be in the current project. You can enforce a project:

/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea <project_path> \1 --line \2

or event use \5 as a project path, \5 is a pwd in the current terminal directory.

I had better results with the first configuration.

Note: with IntelliJ Idea 2019.1 i used: /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea --line \2 \1


I move to pycharm, and I am currently using this line:

/Applications/PyCharm.app/Contents/MacOS/pycharm  \1 --line \2
Community
  • 1
  • 1
Raúl Martín
  • 4,471
  • 3
  • 23
  • 42
  • 1
    Awesome! With eslint I had to use the following formatter to get line numbers to work https://github.com/royriojas/eslint-friendly-formatter – AndiDev Jun 15 '18 at 19:42
  • 3
    WebStorm 2018.3 ignores the --line param if it isn't first, so I had to use: /Applications/WebStorm.app/Contents/MacOS/webstorm --line \2 \1 – Graeme P Nov 29 '18 at 11:02
  • Using Webstorm 2019.2.3 this takes about 5 seconds to detect the current instance. `open -a` is instant, but `--line lineX $file` and `$file:lineX` both ignore the line number. Do you know how to open on the file line with no delay? – zino Sep 30 '19 at 11:32
  • 2
    I had to add quotes around the path. I think because iTerm was launching it with `/bin/sh`: `"/Applications/IntelliJ IDEA.app/Contents/MacOS/idea" --line \2 \1` – Bryan Young Nov 01 '19 at 15:22
  • 2
    `/Applications/RubyMine.app/Contents/MacOS/rubymine --line \2 \1` works for my with RubyMine 2021.1. Make sure you start a new iTerm session after setting the command. – Mark Schneider Jun 23 '21 at 14:52
  • You could put the 2019.1 edit on the initial response, it's been a while now – apflieger Jul 08 '22 at 09:30
12

The accepted answer didn't quite work for me. I ended up using:

open -a "IntelliJ IDEA" \1
starmer
  • 2,197
  • 19
  • 12
  • 2
    Could you get this working with a line number? I tried open -a "IntelliJ IDEA" \1 --args --line \2 but it doesn't work – Graeme P Nov 29 '18 at 11:21
9

I can confirm the following command is working with or without line numbers, when entered into iTerm2 > Preferences > Profiles > Advanced > Semantic History > Run Command:

 [ -z \2 ] && /usr/local/bin/idea \1 || /usr/local/bin/idea --line \2 \1

This makes use of the fact that IntelliJ IDEA installs a command line launcher python script idea to /usr/local/bin, and requires the project in which the file resides to be open (multiple projects can be open, and it will still find the correct one.)

The command checks to see if the line number argument \2 is blank; if it is, it will exclude the line number, otherwise it will specify it with --line. \1 is the filename including the path.

To see all the available options for idea:

/usr/local/bin/idea --help

Environment:

  • iTerm2 3.1.7
  • IntelliJ IDEA CE 2018.1.5
  • macOS High Sierra 10.13.4
  • It works! thank you. Here's my usage that opens both files with and without line numbers `[ -z \2 ] && /Applications/GoLand.app/Contents/MacOS/goland \1 || /Applications/GoLand.app/Contents/MacOS/goland --line \2 \1` – mfink Aug 02 '19 at 14:23
  • It's working for me too, in RubyMine, with and without line numbers. `[ -z \2 ] && /Applications/RubyMine.app/Contents/MacOS/rubymine \1 || /Applications/RubyMine.app/Contents/MacOS/rubymine --line \2 \1` – Mark Schneider Aug 12 '21 at 01:30
7

Here is the command to open a file in WebStorm via Command + Click on a file path .
Go to Settings > Profiles > Advanced > Semantic History > Run command and input

/usr/local/bin/webstorm --line \2 \1

For the IntelliJ Idea this line should work (documentation):

/usr/local/bin/idea --line \2 \1

One of the problem with those solutions is that they only work for file paths that contain a line number like /some/path/to/file.txt:15 and do nothing when the path has no line number like /some/path/to/file.txt.

The most robust solution is:

[ -z \2 ] && /usr/local/bin/idea \1 || /usr/local/bin/idea --line \2 \1
Dmitry Davydov
  • 987
  • 13
  • 21
2

Maybe you can just operate Tools > Create Commandline Launcher in intellij or other jetbrains IDE.

maiyang
  • 1,001
  • 7
  • 3
-3

Just go to intellij. type in keys CMD + Shift + A and type "Create commandline launcher" Enter And click Ok

You are good to go Go to terminal and type idea . to open project in intellij