53

I'm trying to launch IntelliJ on command line in Mac OS X to use it's diff tool. Theoretically idea.sh diff file1 file2 should work. In practice there are some issues with the file which I think I worked around (removing some arguments to readlink etc).
However when it does start, it wants me to enter license information (even though an instance of Intellij is already running and the license is there). Which leads me to believe that there is some sort of separation of command line world vs non-command line world on Mac OS X? IS that true?
Also when I select 30 days eval it proceeds to give me the following exception:

java.lang.IllegalArgumentException: Argument 0 for @NotNull parameter of com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.getProviders must not be null
    at com.intellij.openapi.fileEditor.impl.FileEditorProviderManagerImpl.getProviders(FileEditorProviderManagerImpl.java)
    at com.intellij.openapi.diff.impl.highlighting.EditorPlaceHolder.setContent(EditorPlaceHolder.java:73)
    at com.intellij.openapi.diff.impl.highlighting.DiffPanelState$1.run(DiffPanelState.java:38)
    at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:864)
...
MK.
  • 33,605
  • 18
  • 74
  • 111

9 Answers9

188

IntelliJ can install a command line launcher for you, adding it to a PATH directory would make it as any other commands on the system. The command is "idea".

IntelliJ Command-line Launcher

Meeh
  • 2,538
  • 3
  • 18
  • 20
36

Try running /Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea instead. idea.sh is not designed for Mac and will not work without some manual changes.

Another option is to create the command line launcher: Tools | Create Command-line Launcher.

If you are using Toolbox, it provides the way to create the command launcher automatically.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • It's better - no license issues, but it still gives me the same error (in a dialog box now): Error showing diff: Argument 0 for @NotNull parameter of com/intellij/openapi/fileEditor/impl/FileEditorProviderManagerImpl.getProviders must not be null – MK. Oct 20 '11 at 13:59
  • so this works for diff, but I would like to invoke the merging functionality (be able to save after resolving conflicts). Is this doable? – MK. Oct 27 '11 at 21:10
  • 1
    No, merge is not possible yet, please vote for http://youtrack.jetbrains.net/issue/IDEA-69292. – CrazyCoder Oct 27 '11 at 21:15
  • what is the setup so you can start it from any directory with the following: idea . – Tim Boland Jan 19 '17 at 00:59
  • Is there a way to open a file in a new tab via command line functionality rather than a new instance of Intellij? – MaxRocket Jan 26 '22 at 15:39
33

Try:

Tools > Create Commandline Launcher

This will create a command line launcher. After that you can launch IntelliJ from your desired folder like with a command like this :

idea .

or

idea <path to the folder>
R K Punjal
  • 1,445
  • 1
  • 15
  • 20
15

First step, you'll follow and click the menu, Tools > Create Commandline Launcher you'll run this command on what you want open project's directory.

idea .
  • 3
    When adding an answer to an older question that has answers already it is useful to explain why your answer is different. Can you edit your answer to explain how it differs from the one by Meeh, and how your answer addresses the diff portion of the question? – Jason Aller Jan 30 '19 at 11:21
  • Awesome, should be a answer – Thamaraiselvam Sep 05 '19 at 08:46
8

If you have the toolbox installed, this is now controlled using the Toolbox App Settings.

First enable using the (global) toolbox app settings:

enter image description here

Now, you can enable at the IDE level (here using Intellij):

enter image description here

arcseldon
  • 35,523
  • 17
  • 121
  • 125
6

Idea expects paths to be fully qualified, so I wrote a small helper script. Invoke like:

$ idiff foo.txt bar.txt

The code for idiff:

#!/bin/bash
idea='/Applications/IntelliJ IDEA 10.app/Contents/MacOS/idea'
left=`abspath $1`
right=`abspath $2`
"$idea" diff $left $right

There is probably a real abspath tool somewhere, but I have a simple hand-rolled one:

$ cat `which abspath`
#!/bin/bash
ORIG_DIR=`pwd`
for fn in $* ; do 
  if [ -e $fn ]; then
    d=`dirname $fn`
    if [ -z $d ]; then 
      echo `pwd`/$fn
    else
      cd $d
      echo `pwd`"/"`basename $fn`
    fi
  else
    echo "Don't know how to process $fn" 1>&2
    exit 1
  fi
  cd $ORIG_DIR
done
Andrew E
  • 7,697
  • 3
  • 42
  • 38
1

Tested for the new versions of IntelliJ in 2023: -

add this line in .zhsrc:

alias idea="/Applications/IntelliJ\ IDEA.app/Contents/MacOS/idea"
Ashish Kumar
  • 11
  • 1
  • 3
0

First you must create the shell scripts to open the IDEs, in the latest version it's done on the Toolbox

Toolbox App > Configuration > Settings > Generate shell script > export to a folder like /User/asilva/IDEs

Then you could call it like ./User/asilva/IDEs/idea or ./User/asilva/IDEs/webstorm

But if you want to call it without the absolute path, the it's needed to add it on the $PATH to be loaded every time the terminal is open:

~/.zshrc

(...)

# idea + webstorm
export PATH="/Users/asilva/IDEs:$PATH"

with this, the webstorm or idea command will be globally available

Alejandro Silva
  • 8,808
  • 1
  • 35
  • 29
0

In the case of PHPStorm, you need to do the same - Tools > Create Commandline Launcher but inside Terminal you should use pstorm .

chavy
  • 841
  • 10
  • 20