问题
I have output in my iTerm like:
File project/path/path/file.py:56:54 extra text information
How I can open this file in IntelliJ with a single click?
回答1:
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
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
回答2:
The accepted answer didn't quite work for me. I ended up using:
open -a "IntelliJ IDEA" \1
回答3:
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
回答4:
Maybe you can just operate Tools > Create Commandline Launcher
in intellij or other jetbrains IDE.
回答5:
For those who are using Jet Brains Toolbox App on MacOS. I've made this simple bash script for opening a file from iTerm in the currently installed version of WebStorm. And here is the command to use it in iTerm settings (Settings > Profiles > Advanced > Semantic History > Run coprocess)
/path/to/run_webstorm_launcher.sh --line \2 \1
Thanks to Graeme Pyle for the special argument placement in WebStorm.
Here is the content of run_webstorm_launcher.sh
#!/bin/bash
# Use this to pass an arguments to the latest WebStorm launcher in macOS
# in iTerm > Settings > Profiles > Advanced > Semantic History > Run coprocess
# path/to/run_webstorm_launcher.sh --line \2 \1
"$(grep -o '/.*/webstorm' /usr/local/bin/webstorm)" "$@"
来源:https://stackoverflow.com/questions/40516020/open-file-on-intellij-from-iterm-2