Reputation: 4689
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?
Upvotes: 36
Views: 12273
Reputation: 571
For version RubyMine 2024.1 working with this setting:
# iTerm2 -> Preferences -> Profiles -> Semantic history -> Select:
# Run command... and add this line of code:
[ -z \2 ] && /Applications/RubyMine.app/Contents/MacOS/rubymine \1 || /Applications/RubyMine.app/Contents/MacOS/rubymine --line \2 \1
Upvotes: 0
Reputation: 4689
IntelliJ has a command line features that you can check out here:
https://www.jetbrains.com/help/idea/2024.1/working-with-the-ide-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
In Semantic History check "Run Comand.." and add as a command:
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea --line \2 \1
IntelliJ has to be in the current project. You can enforce a project:
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea <project_path> --line \2 \1
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 --line \2 \1
UPDATE
Several people in the comments and other responses have suggested using --line \2 \1
instead of \1 --line \2
. So, I've updated this in the answer in several places.
Upvotes: 48
Reputation: 3367
https://stackoverflow.com/a/40516021/2499870 answer was almost perfect, although I wasn't getting the line correctly. Inverting the order worked. Putting first the line and then the file.
/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea --line \2 \1
Upvotes: 1
Reputation: 1092
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
Upvotes: 11
Reputation: 1
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
Upvotes: -3
Reputation: 1141
Maybe you can just operate Tools > Create Commandline Launcher
in intellij or other jetbrains IDE.
Upvotes: 2
Reputation:
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:
Upvotes: 11
Reputation: 2277
The accepted answer didn't quite work for me. I ended up using:
open -a "IntelliJ IDEA" \1
Upvotes: 13