Is it possible to open PHPStorm from WSL using pstorm command?

I'm trying out WSL2 on Windows 10 and I'd like to have the same behavior as on a macOS, where in the terminal I can type pstorm . and it will open the current folder in the PhpStorm.

Is this possible?

0
9 comments

I doubt that it is even possible in Windows 10 + WSL as the Windows command line does not support UNC paths.

However, it is still possible to use a generated shell script and open project by specifying the full path, like:

phpstorm2 \\wsl$\Ubuntu-20.04\home\test\myproject

Or you may map your WSL network share to a drive letter and then use the launcher in the same way as on macOS.

0

You can probably write a custom script/alias and use the wslpath command to map paths:

$ wslpath -w /home/ubuntu
\\wsl$\Ubuntu-20.04\home\ubuntu

I've just tried this and it actually worked:

'/mnt/c/Program Files/JetBrains/PhpStorm 2020.1/bin/phpstorm64.exe' $(wslpath -w .)

Whether it's reliable or not, that's something I don't know.

1

You can do this with Toolbox and a shell function.

First set up the Toolbox scripts.

  1. In Toolbox click the hex icon > Settings
  2. Enable Generate Shell Scripts
  3. Enter a path in Shell scripts location. I prefer something like "C:\Users\<username>\scripts\jetbrains".
  4. Close settings and go to the Tools tab.
  5. Click vertical ellipsis icon > Settings.
  6. Make sure Shell script name is "phpstorm". You could name it something else, but make sure you remember what you called it.

Now that the Toolbox scripts are setup you can run the following from the command prompt. The first argument is the path to to the project directory.

C:\Users\<username>\scripts\jetbrains\phpstorm.cmd "C:\<path_to_your_project>"

Or a WSL project

C:\Users\<username>\scripts\jetbrains\phpstorm.cmd "\\wsl$\Ubuntu-20.04\<path_to_your_project>"

To be able to run this form WSL you can use the following...

# .bashrc

phpstorm() {
cmd.exe "/mnt/c/Users/<username>/scripts/jetbrains/phpstorm.cmd" $(wslpath -w ${1:-$(pwd)})
}

Note: this requires that you mount the C: drive in WSL if you have not already done so.

You can then call this function from your shell...

phpstorm <path_to_project>

If no path is specified, it will use your working directory by default. So you could just call...

phpstorm
2

Thanks for the detailed description of how to achieve this. I don't have the Toolbox, instead I've set up the alias like Álvaro González mentioned

alias pstorm="/mnt/c/Program\ Files/JetBrains/PhpStorm\ 2021.3/bin/phpstorm64.exe $(wslpath -w .)"

The only issue I have is that it will open two phpstorm windows - one with the correct project opened, and another LightEditProject called `wsl.localhostUbuntu-201.04pathtoproject`.

Not really sure why, but I just close the second one and it does the trick :) 

0

That second project is pretty strange. I have no idea why that happens.

I would strongly recommend getting Toolbox. I didn't when I first started using JetBrains IDEs, and after I started, it is hard to imagine going back. I also use about four different IDEs every week. Toolbox helps keep my IDEs up to date and my projects easily accessible. I am defiantly a fan.

0

This https://www.jetbrains.com/toolbox-app/ ?

I'm only using PhpStorm from JetBrains, but I'll check it out 👍🏼

0

Yes. That is the one. I use it a lot to open existing projects. It is faster than starting an one of the IDEs and switching to that project with File > Open Recent. It is a little more point and click than opening a project from the terminal, but it is really convenient. I also use the browser extension to clone a Github repo down to my machine as a new project.

0

Actually you can do it via running 

phpstorm64.exe <your path>

To make use of an alias like 'pstorm' or 'phpstorm' you can create an alias in your Linux. I myself have Ubuntu 20, so I put text

alias phpstorm='phpstorm64.exe'

at the end of my 

~/.bashrc

file.

So, right now I can do 


phpstorm .

in my project's folder, and my PHPStorm pops up. Enjoy 🙂

2

For anyone wanting a more up-to-date solution without any errors in the command line, I found this:

https://laracasts.com/discuss/channels/general-discussion/correct-launch-of-phpstorm-from-wsl-in-the-console#reply-904805

0

Please sign in to leave a comment.