If your an advanced WebStorm user you’ve probably noticed the limitations of WebStorm’s shell tools. One glaring example is the inability to open a project with the webstorm ~/path/to/project
command if there is already an project open in WebStorm. Instead of creating a new window with a WebStorm instance like one would expect, the user is simply navigated to the project WebStorm already has open.
To implement a more robust solution than WebStorm’s own shell tools have to offer, a bit of extra script must be introduced to the terminal’s environment. Add the following function to your .bash_profile
(found under ~/.bash_profile
).
# Open WebStorm project
ws(){
for var in "$@"
do
open -a /Applications/WebStorm.app "$var"
done
}
After the script is added, open a fresh terminal session and try out the new functionality by running the following command:
$ ws /some/project/directory
Since the function we added to the .bash_profile
loops through the command’s parameters as well, we can pass in multiple projects at the same time.
$ ws /some/project/directory /some/other/project/directory
These commands will focus the window to the project that is being opened. If you want to just navigate to an already open WebStorm project and not necessarily open a fresh instance of a project, just run the ws
command and point it to the active project’s directory.