Opening a project directory in PhpStorm from the Terminal - bash

I want to open a project directory in PhpStorm using pstorm .
I am aware that there are many threads that have discussed this issue, but I have not been able to completely solve my problem with the solutions from those threads.
Using the IntelliJ Toolbox, I click the gear icon (top right) and I enable the Generate Shell Scripts option. I set the Shell script location to /usr/local/bin (which is in my PATH). The Shell Script Name is specified as pstorm.
The first issue is that the script isn't generated in /usr/local/bin. Presumably since the Toolbox doesn't have write privileges at that location. I then set it somewhere where it has write privileges - something like /home/username/.local/share/JetBrains/Toolbox/bin. The script is successfully generated there under pstorm:
# Generated by JetBrains Toolbox 1.20.7940 at 2021-03-24T16:55:42.325644
"/home/username/.local/share/JetBrains/Toolbox/apps/PhpStorm/ch-0/203.7148.74/bin/phpstorm.sh" "$#"
I then copy that file to /usr/local/bin: sudo cp pstorm /usr/local/bin
I then open a terminal and navigate to my desired directory, opening said directory in PhpStorm with pstorm .
PhpStorm then opens the directory. However, PhpStorm is then 'locked' as a child to the (parent) terminal instance and closing the terminal also closes PhpStorm. A more complete explanation relating to this behaviour is given here
I would really prefer that PhpStorm not be dependend on a terminal instance, much like when I run code . for VSCode.
Any ideas why it is doing this and how to 'solve' this behaviour?

Related

Change directory in terminal using hyperlinks

Opening a gnome-terminal in the specified directory is straightforward:
gnome-terminal --working-directory ~/dotfiles
Creating hyperlinks is not a problem:
echo -e '\e]8;;file:///home/pmn/dotfiles\aThis is a link\e]8;;\a'
this produces a link that opens the file explorer in the correct folder when Ctrl+Clicked.
What I want to do is combine the two things, so that when I Ctrl+Click the link, a terminal pops up, already in the requested folder. It would not be a problem if the current terminal I'm in changed directory, but in that case I'd like to still see the previous terminal output and just do the equivalent of a regular cd (Edit: Note that the ~/dotfiles folder is just an example, I have several links that are generated by a script, and I'd like to be able to click on them to quickly open a terminal where needed).
I tried fiddling with registering custom applications:
In ~/.local/share/applications/mimeapps.list add:
(Note that the use of this file is deprecated, ~/.config/mimeapps.list should be used, if you have tips on doing that properly I'm open to them)
[Default Applications]
x-scheme-handler/mygnometerm=mygnometerm.desktop
In ~/.local/share/applications/mygnometerm.desktop add:
[Desktop Entry]
Type=Application
Terminal=false
Name=My Gnome Terminal
Exec=/bin/gnome-terminal --working-directory=%f
MimeType=x-scheme-handler/mygnometerm
Create the folder for the mime database:
mkdir -p ~/.local/share/mime/packages
Update the mime database:
update-mime-database ~/.local/share/mime
This does work: if I right-click on a folder in the file explorer and select My Gnome Terminal as the app to use, a terminal is opened already in the right folder.
If I print
echo -e '\e]8;;mygnometerm:///home/pmn/dotfiles\aThis is a link\e]8;;\a'
and click on the link, a terminal does pop up, but in the root folder, and the same happens when running
gio open mygnometerm:///home/pmn/dotfiles
I just need to combine everything, but I tried a lot of combination of what to echo in the link and could not find the right one.
I'm also open to other ways to achieve this behaviour, but at this point I'm quite curious in how to to it this way.
The use case, for the curious, is that I made a simple script to check the status of my repos, and I want to click on the ones with things to do without having to copy and paste the path. I reckon I'll save at least 5 seconds!
Cheers!

Read only for open directories in vim

Then I open vim from terminal and open an directory like vim ., my starts in Read Only Mode.
I cant figure out why this happen and how I can change it.
If I start MacVim everything is fine. But then I start vim from the terminal and open a directory this screen comes. I can navigate one dir up and back again, and I have write access.
EDIT
I installed all my vim settings on Ubuntu 15.04. Now I can use
Does anybody know how to change this behaviour of vim?
Now I can use netw with the command vim . like I always used.
As you can see, there is no RO (read only) mark. How can
I have this in Mac on iTerm too?
What you see is exactly what you are supposed to see when doing $ vim .: the built-in netrw plugin displays a listing of the current directory that you can use to navigate your project.
If you don't want that listing, don't ask for it:
$ vim
or:
$ vim file
ctrl-p is not mapped by netrw; on my system, its set up by the yankring plugin. If vim is doing something other than going up one line, then you have a plugin involved. Try using :map to see what its mapped to; then do a search for that in your plugins directory.
The netrw way of opening a file in the same window is to use the <enter> key, although the g:netrw_browse_split variable may be used to change that default behavior.
Netrw opens in read-only mode, and that's not going to change. The file being opened should not be in read-only mode, however, if that's what you meant. If you're having a problem of that sort, please update your netrw; the most up-to-date version is at http://www.drchip.org/astronaut/vim/index.html#NETRW .
After I installed macvim 7.4 Every thing works!

How to open webstorm from terminal

To edit files from terminal I use subl (for sublime text) in order to edit the file;
example: If i need to edit app.js file I use subl app.js
Is there any way I can set up webstorm to open from the terminal ?
Try in terminal 'wstorm' and 'webstorm'
If the commands don't work you can run in WebStorm: "Tools" -> "Create Command Line Launcher..."
Note: The solution works only for Linux / MacOS
Update January 2016 using Webstorm 11.0.3 on mac os x
There was no option as described in the accepted answer.
Instead, just use the already installed command line binary wstorm designed for this purpose. Location shown below:
If you actually wish to open webstorm and have it load the contents of the current working directory for example, then place a . after the command:
wstorm .
Noted, others had made similar comments in this answers section, and wished to clarify the situation.
In Webstorm 2020.1.2 you need to do it via JetBrains ToolBox Settings. To do that go to JetBrain Toolbox, click on the settings cog, open Shell Scripts and type the path: /usr/local/bin click apply. Go to your terminal, from your project folder type webstorm . Hope this helps.
As suggested by Ali Faris(comment below), if you have an error like this Shell Scripts failed: /usr/local/bin/webstorm (Permission denied): inside of the logs
Jetbrains Toobox -> settings -> show log files -> toolbox.log (for me in: ~/Library/Logs/JetBrains/Toolbox).
Change /usr/local/bin to another folder name of your choice with the correct access rights, e.g - I chose this name: ~/.jetbrains-launchers.
You can check if script is created by Jetbrains: ls ~/.jetbrains-launchers (you should see a script for each of the jetbrains applications you use).
Add this to your path if needed for example if you use zsh add this at the bottom of your .zshrc export PATH="$HOME/.jetbrains-launchers:$PATH"
Open a new terminal window and this should work.
Basically jetbrains will create script like this (in this case for webstorm cat ~/.jetbrains-launchers/webstorm):
#!/bin/bash
#Generated by JetBrains Toolbox 1.22.10970 at 2022-01-08T12:57:24.803251
declare -a ideargs=()
declare -- wait=""
for o in "$#"; do
if [[ "$o" = "--wait" || "$o" = "-w" ]]; then
wait="-W"
o="--wait"
fi
if [[ "$o" =~ " " ]]; then
ideargs+=("\"$o\"")
else
ideargs+=("$o")
fi
done
open -na "/Users/[YOUR-USER]/Library/Application Support/JetBrains/Toolbox/apps/WebStorm/ch-0/213.6461.79/WebStorm.app/Contents/MacOS/webstorm" $wait --args "${ideargs[#]}"
I also downloaded WebStorm and wanted to use a similar shortcut to open files directly from the terminal.
I was surprised to find I already had a shortcut in my command line tools for webstorm:
subl is to Sublime as wstorm is to Webstorm.
Otherwise, as anstarovoyt has kindly pointed out, you can simply create your own shortcut via "Tools" > "Create Command Line Launcher"
Another way to do that:
open -a /Applications/WebStorm.app #Open last project
open -a /Applications/WebStorm.app Desktop #Open particular folder
open -a /Applications/WebStorm.app Desktop myscript.js #Open particular file
You can add alias to your config file:
#Edit your config:
vim ~/.bashrc
#add line:
alias ws='open -a /Applications/WebStorm.app'
#Read your config file:
source ~/.bashrc
Now you can use it:
ws . myscript.js
I know this is an older thread, but trying to achieve this using Windows was kind of a pain and I wasn't able to find anything specifically designed for my purposes. I created a Bash function that you can add as an alias (for Git Bash on Windows) that works similar to the command line functions in Visual Studio Code.
Here's the link to the Gist.
If you change the integrated terminal in WebStorm to Git Bash (instructions included in the Gist), you can perform the following actions:
Create a new file in the current working directory and open it in the editor:
wstorm foo.js
Create a new file in an existing relative path and open it in the editor:
wstorm foo/bar.js
This also works with subdirectories that don't exist:
wstorm this/path/doesnt/exist/file.js
If you're working in a Git Bash terminal (not in WebStorm) and want to open WebStorm up in the current directory, you can open it similar to Visual Studio Code:
wstorm .
Note: This needs to be done in a directory with a .idea folder.
As of 2019-03-09, WebStorm 2018.3.4 on Mac does not have Tools > "Create Command Line Launcher...". However, this works:
WebStorm Preferences > Keymap > Main Menu > Tools > Create Command-line Launcher...
Right-click "Create Command-line Launcher..." > Add Keyboard Shortcut
Assign a keyboard shortcut
Close Preferences
Type the keyboard shortcut to open "Create Launcher Script"
Click Ok to run the script
You can now launch WebStorm from the terminal with webstorm and can choose a directory to open
After setting up WebStorm to create the cli launcher you actually want to run
wstorm . &
to run the IntelliJ on the background otherwise IntelliJ closes if you happen to close the terminal you have launched the app from.
In WebStorm IDE, click DOUBLE CLICK ON SHIFT and type Create Command Line Launcher then click OK from luncher script promote .
cd project_folder_path using terminal and type webstorm ./ .
that is not for Windows OS
In Ubuntu terminal type:
/var/opt/webstorm6/WebStorm-129.664/bin/webstorm.sh
Note: please see your WebStorm build version, code mine is 129.664
In the terminal, while being in the given project folder:
webstorm .
I know that this is a pretty old thread, but I recently came across this problem on Windows (I'm using the JetBrains Toolbox).
With the following steps all new and existing applications that have been installed with the Toolbox will be added to your path!
Follow these steps to achieve this:
Because of permissions, we need to create a new directory in your user. I named it .path, so that I can also store any other application there in the future. So this will be C:\Users\<PC_USER>\.path\.
The the Toolbox click on the gear icon in the top right corner.
Then click on Enable Shell Scripts and/or Generate Shell Scripts.
In the input field that is located under the switch paste your path folder. (C:\Users\<PC_USER>\.path\)
Open your Edit the system environment variables program that can be found in Windows search or the control panel.
Click on the Environment Variables... button that is located in the right corner, a new window should pop up.
In the new window select the variable that says Path in the Variable column from the top list and then click on the edit button that is situated under the top list. Another new window should pop-up.
Click on new and paste your path there. (C:\Users\<PC_USER>\.path\)
Click on Ok in Edit environment variable > Environment Variables > System Properties.
Go to C:\Users\<PC_USER>\.path\ and all your toolbox installed applications should be there.
Restart your CLI and it should work.
The wstorm command didn't work in my Git bash, so I added the following function to my .bash_profile instead:
wstorm() {
/c/Program\ Files\ \(x86\)/JetBrains/WebStorm\ 2016.2.2/bin/WebStorm.exe $PWD/$1
}
A short solution relevant to the year 2021 for Linux users.
Just execute the comand:
sudo ln -s /<your path to Webstorm directory>/bin/webstorm.sh /usr/local/bin/webstorm
Since /usr/local/bin should be in the PATH environment variable by default, you should be able to run the webstorm command from anywhere in the shell.
More details Webstorm docs
I am running Windows 10 and whipped up a batch file (ws.bat) that implements this with optional command line argument for path to load).
:: place this batch file in your path and set to your WS EXE
:: ref: https://www.robvanderwoude.com/battech_defined.php
:: author: bob#bobchesley.net
#echo off
set target=%1
if defined target (goto passedarg) else (goto noarg)
:passedarg
echo Starting WebStorm with '%target%'
"C:\Program Files\JetBrains\WebStorm 2018.3.2\bin\webstorm.exe" %target%
goto:EOF
:noarg
echo Starting WebStorm with 'Current Dir'
"C:\Program Files\JetBrains\WebStorm 2018.3.2\bin\webstorm.exe" .
Pretty simple but it works.
webstorm . doesn't work on Windows. Try this for the current folder:
webstorm $pwd
$pwd is the current folder's path

Open an ipython notebook via double-click on osx

I've downloaded a couple of ipython notebooks, and I'd like to open them in browser tabs without navigating to the directory I've downloaded them to and running ipython notebook notebook_name.ipynb.
I realize this probably means I'm lazy, but it seems like a common use case to me. Am I missing something obvious?
Use Pineapple application for opening and working on your IPython/Jupyter notebooks. It is pretty cool.
Update:
Now there is nteract, which is a new jupyter-like Desktop app. After installing it, make it the default app for opening .ipynb files. Then just double-click any notebook to start it right away.
I have found a nice way using Automator (Oct. 2017; with information from here):
open Automator and create a new Application
to add Run Shell Script drag and drop it from the list; might need these settings Shell: /bin/bash and Pass input: as arguments
insert the code below; if necessary adjust the path to jupyter
Code
#!/bin/sh
variable="'$1'"
the_script='tell application "terminal" to do script "/usr/local/bin/jupyter notebook '
osascript -e "${the_script}${variable}\""
save the script as an application (!)
try to open a .ipynb file and change the default app to this newly created one.
notes
This will open a terminal and run the jupyter notebook command, such that you can interrupt and stop the notebook-server from there.
Also note that you cannot test the app like that in Automator, but need to add the Get Specified Finder Items and insert some test notebook there (just for testing purposes).
As pointed out in the comments, there are two more notes:
To avoid spamming your browser history with notebooks, you can start your notebooks in incognito/private mode: Run jupyter notebook in incognito window
If you want to run notebooks in one server and don't mind an extra tool, Sachit Nagpal has pointed out (thank you), that one could also use nbopen. To use this workflow just replace "/usr/local/bin/jupyter notebook ' with "nbopen '. Any other tool should work alike.
pip install nbopen.
open Automator, create new Application
Drag'n drop Run Shell Script
Change Pass input to as arguments
Copy/paste this script:
variable="'$1'"
the_script='tell application "terminal" to do script "nbopen '
osascript -e "${the_script}${variable}\""
Save the new application to Applications directory as nb_open
Right click any ipynb file and select "Open with > Other" and select the nb_open in the Applications folder. Don't forget to check "Always Open With".
Select an ipynb file, get info (command + i) > Open With (select nb_open if not selected already) > Click Change All.... Done.
The application posted here worked pretty well for me: http://bioequity.org/2013/11/16/ipynbviewer/
You also need to download iTerm2, as described on that page.
Note that this doesn't work if there are spaces in the filename, but you can modify it so that it works with spaces in the filename. Control-click on the iPyNbViewer.app and select "Show package contents". Edit the file Contents/Resources/Scripts/main.scpt. Change three instances of "POSIX path" to "quoted form of POSIX path". Now it will work with spaces in the filename.
To set all of your .ipynb files to open with the app, you'll need to Get Info (command-I) on one of the files and select the iPyNbViewer app to open all .ipynb files.
It would be great if this was the default behavior of double-clicking on an iPython notebook file...
I came up with a way of doing it on Ubuntu. (It works for me but I can take no responsibility). It's explained here. In a nutshell, you need to create a new MIME type, then write a script that works as the app that launches them:
#!/bin/bash
netstat -tln |grep "8902"
# if not found - equals to 1, start it
if [ $? -eq 1 ]
then
ipython notebook / --no-browser --port=8902 &
sleep .5
fi
xdg-open http://localhost:8902/notebooks$1
This always opens the notebook server on port 8902, but first checks whether there is already a server running, and, if so, uses it.
Then you can use ubuntu tweak to select your script as a default application for the MIME type "IPython Notebook" you just created.
Not very elegant, but worth it, in my opinion.
PyCharm now supports Jupyter ipynb files:
which is from the documentation https://www.jetbrains.com/help/pycharm/editing-jupyter-notebook-files.html.
But I think this feature is only available in the Professional version now; hopefully it will be added to the Community version in the future.
Look at this link.
Put a bash script in the folder where you keep your ipython notebooks and simply double click it to open up a notebook instance. From the link above, the bash script has just:
path=$0 # path is path to this file
cd ${path%/*.*} # clip off the file name to get directory path and cd
ipython notebook --pylab inline
Finally, you need to chmod u+x the script to make it executable and you're done.
I have used the command line application 'nbopen' and put it in a Platypus wrapper to get drag'n drop and double click opening on Macos. 'nbopen' is downloadable using 'pip'
It works well when used as described above by DanHickstein.
Only problem with my code is that it requires the full path to the nbopen command. I know I should be able to use 'which nbopen' somehow but can't get it to work.
Heres my Platypus code:
#!/bin/bash
# Opens ipynb files in a Jupyter Notebook
# echo $1
# $1 is the path of the dropped file
/Users/robw/anaconda/bin/nbopen $1
# Based on an idea from
# https://www.quora.com/Is-there-a-straightforward-way-to-open-an-IPython-Notebook-in-Windows-by-double-clicking

RVM is not being used by Ubuntu Launcher

I'm trying to make my data files "clickable" like a MS Word document. When a user clicks on a file on the desktop with a ".vr" extension, I want it to execute my Ruby script, and pass the file name as a parameter.
I've created a mime type, "text/vr" with the ".vr" extension, and when I click the file, "text.vr" on the desktop, it attempts to run the command:
$vr test.vr
This command fails because it tries to use an old version of Ruby. The problem is that Ubuntu uses a different environment when it launches a program from the desktop instead of the prompt.
I use RVM, and it works perfectly when I write programs in the terminal. However, when I click on the file to launch the vr script, RVM isn't used. I need to find a way to make RVM load when a file is clicked.
What's going on here? What environment file is loaded when you execute a file from the desktop? ~/.bashrc? ~/.profile? How can I make it so my whole computer always finds RVM?
Thanks,
Eric
There are few ways, the environment for desktop is loaded from .profile, add one of this:
source $HOME/.rvm/environments/ruby-1.9.3-p327 #OR:
source $HOME/.rvm/environments/default
to load specific ruby.
sometimes it might not work with sourcing, then adding content of the default file to .profile should work:
cat $HOME/.rvm/environments/default >> ~/.profile
It is required to relogin / restart to apply the changes.

Resources