DEV Community

Cover image for Open your files with PhpStorm from iTerm2
Ivan Brcko for Bornfight

Posted on

Open your files with PhpStorm from iTerm2

Did you ever CMD + click on a file path in your iTerm2 and expected that file to open in your beloved PhpStorm editor only to experience that exact file to open in TextEdit, Sublime, or something else?

Look no further, open your files in PhpStorm like a pro!


Here is the simplest of NodeJS index.js scripts:



// index.js

var http = require("http");

http.createServer(function(request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.write("Hello World. This page is running Node.js version: ");
  response.write(process.version);
  response.end();
}).listen(3000);


Enter fullscreen mode Exit fullscreen mode

The road to hell,



// index.js

var http = require("http");

http.createServer(function(request, response) {
  ...
  throw new Error('Oops 🤷🏻‍♂️'); 
  ...
}).listen(3000);


Enter fullscreen mode Exit fullscreen mode

image

...is paved with good intentions.


Firstly - you'll need to create a command-line launcher for your PhpStorm executable.

If you are not using JetBrains Toolbox:

  • Tools   ➡️   Create Command-Line launcher 

If you are using JetBrains Toolbox:

  • Open the Toolbox and click on the gear icon, and then on "Settings":

image

  • Configure your shell script name:

image

  • You might need to enable shell scripts, if so, do the following: image

image

Secondly - you'll need to configure your iTerm2 to open files in PhpStorm

  • Open iTerm2 preferences

  • Go to:
    Profiles   ➡️    Advanced   ➡️    Semantic history

  • Expand the dropdown menu:
    image

  • Select "Run coprocess..." and paste in the following:
    /usr/local/bin/phpstorm --line \2 \1
    Or something else, depending on what you configured in the first step

Thirdly - reap the benefits

Voila, now when you CMD + click on a file path in iTerm2, the file will open in your beloved PhpStorm, with the selector at the respective line.

Happy file opening ✌🏻

Top comments (0)