Can I open a directory from command line?

Answered

I want to open a directory as a project from command line.

such as

$ /Applications/PhpStorm.app/Contents/MacOS/phpstorm ./ 

or

$ /Applications/PhpStorm.app/Contents/MacOS/phpstorm /path/to/new/directory 

But it fails.

Is there a way to do this?

Thanks.

16 comments
Comment actions Permalink

Hi there,

I'm not a Mac user .. but as far as I know you should use "Tools | Create Command-line Launcher..." first -- it should create a "pstorm" script/launcher (whatever it's properly called) which you can use to launch your PhpStorm from terminal.

  • "pstorm ." -- this should open PhpStorm and open (or create if does not exist) project in current folder (that pstorm script should expand "." into full path and launch PhpStorm with full path as argument
  • "pstorm /full/path/to/some/dir" -- this should open PhpStorm and open (or create if does not exist) project in that specific folder

https://www.jetbrains.com/help/phpstorm/2016.2/working-with-phpstorm-features-from-command-line.html?search=command

If it still fails -- please check "idea.log" file (Help | Show Log in...) for possible hints.

7
Comment actions Permalink

Thanks Andriy Bazanov!

That is the way I want to do!

$ git clone http://github.com/foo/bar
$ pstorm .

Then I can open PHPStorm and make it a project.

Really Thanks!

0
Comment actions Permalink

Almost OK but I have a little problem.

I can open a directory when I closed PHPStorm.
But I cannot open a directory when I already opened PHPStorm project.

pstorm command does not open a new tab.

Any ideas?

Thanks.

2
Comment actions Permalink

What's the exact command you're entering while IDE is opened? 

There might be an issue with this: https://youtrack.jetbrains.com/issue/IDEA-103537 - for some users IDE won't open another project with a `pstorm` command while IDE is running.

0
Comment actions Permalink

Thank you Dmitry Tronin.

The command is

pstorm .

But it just focuses to PHPStorm.app.

It might be the same issue you told me.
I give up to open a directory from command line.

Thanks!

1
Comment actions Permalink

My friends solve the problem!

$ open -a IntelliJ\ IDEA\ 15 ./

or

$ open -a PhpStorm ./

 

Thanks!

13
Comment actions Permalink

@Satoshi's version works for me.

The problem I found with `pstorm` is that `pstorm` would not open another directory if there are already opened project(s). :/

1
Comment actions Permalink

@Phillip

I aliased the open command it really helps me.

such as

 $ alias op='open -a PhpStorm'
$ git clone https://github.com/yousan/dotfiles
$ op dotfiles

   

 

4
Comment actions Permalink

Sorry, but the suggested solution stopped working after upgrade to macOS Catalina. Before it was working fine. Any suggestions?

 

0
Comment actions Permalink

I'm using Catalina, and still use it all the time. However, I'm using Intellij now:

    $ alias op
    op='open -a IntelliJ\ IDEA'

 

1
Comment actions Permalink

Philip Z your suggestion did not work for me either.
Sorry, I should provide more context in my original question:
- I`m on macOS Cataline, version 10.15.5
- I`m using JetBrains Toolbox App, version 1.17.7018 (https://www.jetbrains.com/toolbox/app/), but not a standalone installation
- PhpStorm version is 2020.1.2

I was trying to link `~/Library/Application\ Support/JetBrains/Toolbox/apps/PhpStorm/ch-0/201.7846.90/PhpStorm.app` into `/Applications/PhpStorm.app`. But that did not work.


Eventially, following command worked out for me:

/open -a ~/Library/Application\ Support/JetBrains/Toolbox/apps/PhpStorm/ch-0/201.7846.90/PhpStorm.app ./

And that is cool, the only thing i`m considered about is the fact I would need to adjust this alias for further PhpStrom updates. Or is there a more flexible solution in my case?

0
Comment actions Permalink

@Dolgushev Serhey

What about built-in command line launcher? AFAIK the Toolbox App can generate them...

This ticket for example (https://youtrack.jetbrains.com/issue/TBX-4527) say it fixed some stuff... so it should work (sorry, I'm a Windows user that does not use Toolbox App)

0
Comment actions Permalink

Seems like it is indeed something similar to https://youtrack.jetbrains.com/issue/TBX-4527. Andriy Bazanov should I submit a separate ticket for my case?

0
Comment actions Permalink

@Dolgushev Serhey

Accordingly to your 1.17.7018 version (which is newer than 1.17.6802 fix version from the ticket) it should be working. Maybe you just need to regenerate the launcher?..

If it would be me I would comment there in the ticket first providing my info and see what the devs will say. If somehow I get no response in few days or they tell "we need to investigate more" then I would do a new ticket.

Check the idea.log file anyway (Help | Show log in Finder...)

 

0
Comment actions Permalink

no such thing as sorry or should, any s k

 

0
Comment actions Permalink

In PhpStorm 2021.2.1 works for me likes Satoshi Kamigaki.

aliased command to open PhpStorm

alias phpstorm="open -a PhpStorm"
$ cd ~/MyProject
$ phpstorm .
2

Please sign in to leave a comment.