How to change default eclipse shell interpreter? - eclipse

I have installed the ShellEd plugin in eclipse. Whenever I run a bash script it runs it using dash even if I specify interpreter directive #! /bin/bash at the top of the script.
How do I change this behavior?

You need to install Cygwin or MSYS/MinGW.
Add the interpreter bash.exe path in eclipse as follows:
Window->Preferences->Shell Script -> Interpreters

THere should be an option to set the bash interpreter as follows:
Window->Preferences-><the_plugin_name>->Interpreter.
you need to set you bash interpreter path here (/bin/bash).
Eclipse will use the value you set here to execute your program.

In new versions of Eclipse current v2.23.0 and beyond the path to change terminal is:
Windows > Preferences > Shell > Local Terminal, under subtitle Show in there is a button labeled Add

Related

How to use Python3 on the VScode terminal?

Is there a way to force VS Code to use only python3? It always defaults to python2.7 no matter what I try. I've tried selecting the correct interpreter as python3.7. When I open up terminal, it immediately uses python2.7, In the settings it is pointing at 3.7, but the built in terminal which is nice, always defaults to 2.7.
First, understand that the integrated terminal of VSCode, by default, uses the same environment as the Terminal app on Mac.
The shell used defaults to $SHELL on Linux and macOS, PowerShell on
Windows 10 and cmd.exe on earlier versions of Windows. These can be
overridden manually by setting terminal.integrated.shell.* in user
settings.
The default $SHELL on Mac is /bin/bash which uses python for Python2.7. So VS Code will just use the same python to mean Python2.7. When you open a bash shell, it will load your ~/.bash_profile to apply custom aliases and other configurations you added into it.
One solution to your problem is edit your ~/.bash_profile to alias python to python3. But I do not recommend this because this affects all your bash sessions, even those outside of VS Code. This can lead to nasty side effects when you run scripts that need python to be the system Python2.7.
You can instead configure VSCode to load its own aliases, for its own integrated terminal. First, create a file named vscode.bash_profile in your home directory:
$ cat ~/vscode.bash_profile
alias python=$(which python3)
On my env, python3 is Python3.7. You can set it to the what's applicable on your env (ex. maybe python3.7). Then, in VS Code, look for the Terminal shell args setting:
and then open your settings.json and add these lines:
"terminal.integrated.shellArgs.osx": [
"--init-file",
"~/vscode.bash_profile",
]
Finally, restart VS Code. The next time you open the VS Code terminal, python should now be using your Python 3 installation. This should not affect your bash session outside of VS Code.
Note that, if you have some custom settings from the default ~/.bash_profile, you may want to copy it over to your ~/vscode.bash_profile, so that you can still use it on VS Code (ex. changes to PATH, git-completion scripts..).

How to open cygwin & execute bash in Eclipse?

I am trying to build my custom-commands in Eclipse.
This is Eclipse plugin which I am using: https://marketplace.eclipse.org/content/startexplorer
It looks like this (link to image):
Custom commands in Eclipse
I need eclipse variables in custom commands:
${resource_loc} , ${selected_resource_loc} , ${workspace_loc} , etc...
It should be something like this:
D:\cygwin64\bin\mintty.exe /bin/bash -l -c "cd ${workspace_loc}"
But mintty will close this window immediately. I need to execute command based on eclipse variable and go to bash interactive mode, without closing window.
To create a StartExplorer custom command, that opens a Cygwin terminal and
starts an interactive Bash shell in the filesystem location of the selected
resource, follow these steps:
Make sure to install chere
Cygwin package;
Install StartExplorer
Eclipse plugin;
In Eclipse Preferences for plugin StartExplorer, create a new custom
command:
Command: D:\cygwin64\bin\mintty.exe -e /bin/xhere /bin/bash
"${selected_resource_loc}"
Enabled for Resources: yes
Name for Resources Menu: Cygwin Bash Here
Resource Type: Folders
Alternatively to steps 2 and 3, if you don't care about context-menu entry, no
need to install the StartExplorer plugin.
Eclipse Extenal Tools Configuration standard feature will do the trick.
In Run > Extenal Tools Configuration, create a new Program:
Name: Cygwin Bash Here
Location: D:\cygwin64\bin\mintty.exe
Arguments: -e /bin/xhere /bin/bash "${selected_resource_loc}"
Basically, the xhere script (part of chere package) performs the following steps:
indicate to the login shells not to cd $HOME (export CHERE_INVOKING=true, which is checked for in /etc/profile);
change to the directory passed as 2nd argument (cd "$2");
Execute the shell passed as 1st argument as a login shell (exec -l $1).
Note: if you replace /bin/bash with /etc/passwd, the current user's login shell read from /etc/passwd is used instead of bash.

Configure Eclipse to use bash login shell for Cygwin toolchain

I have a custom Makefile project in Eclipse and although the build does get run in a Cygwin shell... it does not seem to be a login shell (bash --login) as it doesn't set my environment variables like running cygwin.bat does.
Where in Eclipse can I change the shell command so that it will be a login shell?
What you actually aim with bash --login are your settings from /etc/profile.
Under UNIX you normally have only one login shell and so these settings are inherited by all other shells. Under Windows any Bash window is an isoloated login shell, which leads to missing environment settings when running Bash from tools that run bash simply as command processor.
I had a similar problem with Emacs compile feature. The best solution under Windows is to set the environment variable BASH_ENV to a script. Bash will execute this script when started without -i or --login, so that /etc/profile is not run. Hence the script will setup Bash for non-interactive, non-login shells.
Example:
BASH_ENV=%USERPROFILE%\.bash_env
as user environment variable. The least thing to do in this script is to set PATH as in /etc/profile:
PATH="/usr/local/bin:/usr/bin:${PATH}"
Check the path-settings in /etc/profile as it is created by Cygwin's setup.exe. You may also copy settings from ~/.bashrc or source this script.
Hope this helps.

How to open a directory in PHPStorm or IntelliJ (or any JetBrains IDE) from the command line?

Is there a way to open up a directory in PHPStorm or an equivalent Jetbrains IDE from the command line? For example, in Textmate, I would just do:
mate .
to open the working directory.
Use Tools -> Create command line launcher and then you can execute pstorm .
Here's how I got IntelliJ Command-line launcher to work with MAC Sierra
(v 10.12.2).
This works with IntelliJ IDEA:
Tools -> Create Command-line Launcher..
Replace 'idea' in the string '/usr/local/bin/idea' with whatever you wish.
(I use 'ij'), so for me its '/usr/local/bin/ij'.
Open your terminal
Navigate to the project/folder you want to open.
Write the chars you wrote after 'bin/' and then '.'
For me its ij .
On OS X: open -a 'phpstorm.app' file-or-folder
For PhpStorm on Windows:
Add the PHPStorm's installation path to the Environment Variables "PATH" variable,
Scroll to the project folder in the command line
Issue the command phpstorm64.exe . if it is 64 bit machine or phpstorm.exe . for 32 bit machine.
I presume the same strategy will work for IntelliJ as well.
Here is the menu entry for v2016.2:
After that you can open folders with pstorm {myfolder}.
Hope it helps.
If you see this message
for Intellij 2019.+ please check this answer. It uses Jetbrains toolbox.
You just need to set path in Generate shell scripts option to /usr/local/bin/ in Jetbrains toolbox
https://stackoverflow.com/a/56050914
and then just run idea .
or pycharm . , phpstorm . etc.
On MacOs
edit ~./bash_profile
add this line
alias pst="open -a 'phpstorm.app'"
Source it
source ~./bash_profile
Now you can open phpstorm in a directory with
pst .
If you are using the JetBrains toolbox, you can configure the shell script for each IDE by going to
settings of the IDE in the toolbox (three dots > settings)
configuration
shell script name
Set it to any text you want
So the method Tools > Create command line launcher... no longer exists in OSX Intellij 2019.1
You can manually make this change via:
vim /usr/local/bin/idea
Change these lines appropriately from old version to new. should be something like this:
RUN_PATH = u'/Users/blahblah/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/191.6183.87/IntelliJ IDEA.app'
CONFIG_PATH = u'/Users/blahblah/Library/Preferences/IntelliJIdea2019.1'
SYSTEM_PATH = u'/Users/blahblah/Library/Caches/IntelliJIdea2019.1'
If you don't know the new path then run something like:
ls /Users/blahblah/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U
or manually navigate via finder, then drag/drop the IntelliJ IDEA.app icon from finder into your cli to copy across the full path.
I`m using JetBrains Toolbox to get the latest updates. And the only solution which worked for me (macOS) is:
Add the following function into ~/.bash_profile
phpstorm-open-current-path() {
PHP_STORM_CH=~/Library/Application\ Support/JetBrains/Toolbox/apps/PhpStorm/ch-0
PHP_STORM_LATEST_VERSION=$(ls -rA1 "${PHP_STORM_CH}" | head -1)
open -a "${PHP_STORM_CH}/${PHP_STORM_LATEST_VERSION}/PhpStorm.app"
}
Reload the changes by opening a new terminal, or running the following command in the current one:
. ~/.bash_profile
Use it:
cd <PROJECT_DIR>
phpstorm-open-current-path
It should be pretty easy to adopt it for any other IDE/OS.
1- add the phpstorm installation path to the path system variable
2- in project folder in address bar type "cmd".
3- in cmd type "phpstorm64 .".

Launch mac eclipse with environment variables set

My company provides an eclipse based development environment which needs some environment variables setting up for the underlying toolchain so multiple versions can be installed concurrently and not take over the system.
I want to provide an icon in finder or the dock which sets these then launches eclipse so customers cannot accidentally launch eclipse without the environment being set. This is what I have tried so far:
Setting environment in Info.plist
for eclipse:
This should be a nice way to do it
but I cannot make it add to the
existing path (like export
PATH=/myapp/bin:$PATH).
bash script wrapping eclipse:
I created a bash script called
eclipse.command to set the
environment then launch eclipse.
This opens a terminal window as well
as the eclipse icon and allows
people to "Keep on dock" for the
bare eclipse. I cannot put
eclipse.command on the dock as it is
not an application.
Applescript wrapping eclipse.command:
An Applescript wrapper around
eclipse.command makes it look like
an app and prevents the terminal
window appearing. Unfortunately I
now get a dock icon for the
applescript and one for eclipse so
can still keep the bare eclipse on
the dock.
Any suggestions? Am I going about this in completely the wrong way?
There is an alternate solution which involves replacing the executable that is run by MacOS X when the user launches the Eclipse application with a shell wrapper that sets up the environment.
Create an empty text file called "eclipse.sh" in the Eclipse application bundle directory /Applications/eclipse/Eclipse.app/Contents/MacOS.
Open the eclipse.sh in a text editor an enter the following contents:
#!/bin/sh
export ENV_VAR1=value
export ENV_VAR2=value
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $#
In the example ENV_VAR1 and ENV_VAR2 are the environment variables being set up. These variables will be visible to processes launched from within Eclipse. The logger command will just log the path of the eclipse executable to the system.log as a debugging aid.
In the Terminal set the executable flag of the shell script eclipse.sh, i.e.:
chmod +x /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse.sh
Open the Eclipse.app Info.plist and change the value for the key CFBundleExecutable from eclipse to eclipse.sh.
MacOS X does not automatically detect that the Eclipse.app's Info.plist has changed. Therefore you need to force update the LaunchService database in the Terminal by using the lsregister command:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/eclipse/Eclipse.app
The next time you launch Eclipse.app from the Dock or from the Finder the environment variables should be set.
I created the following:
alias start-eclipse='open /Applications/eclipse/Eclipse.app'
If you run start-eclipse from the command line, all env vars will be picked up. This way, you only need to maintain a single set of env vars across both command-line and eclipse environments.
Take a look at a related question: Environment variables in Mac OS X.
Basically, this involves the creation of a ~/.MacOSX/environment.plist file.
Log out and Log in for the environment.plist to get picked up by .App's
This worked perfectly in OS X Yosemite:
Open /Applications/Automator.
When the drop-down appears asking you what kind of document you want to create, choose "Application."
In the second-from-the-left list, double-click "Run Shell Script."
In the right side delete the "cat" that gets put there automatically, and replace it with this:
source ~/.bash_profile && /Applications/eclipse/Eclipse.app/Contents/MacOS/eclipse
Now go to File->Save, and save the application to your Applications directory. I named it "Eclipse" with a capital 'E' so as not to conflict with the "eclipse" directory I already had. For good measure, you can even give it the Eclipse icon by selecting the real eclipse app, pressing command-i, selecting the icon, pressing command-c, then selecting the automator "Eclipse" app, pressing command-i, selecting the icon, and pressing command-v.
Now you can open the app, or even drag it to your dock. Note that if you start it, the "real" eclipse will still show up in your dock as a separate icon, but you can't have everything. :)
sakra's answer above is awesome, except is doesn't automatically inherit your existing bash environment. To ensure eclipse.sh picks up your existing bash environment, modify eclipse.sh to use bash instead of sh and add a line to source your existing ~/.bash_profile thus:
#!/bin/bash
source ~/.bash_profile
logger "`dirname \"$0\"`/eclipse"
exec "`dirname \"$0\"`/eclipse" $#
None of the above worked for me. you have to set Eclipse -> Preferences -> Terminal -> Arguments set to --login
That will instruct Eclipse to login with your account just after opening Terminal.
See screenshot:
Reference: https://marketplace.eclipse.org/comment/4259#comment-4259
Link to Eclipse doesn't use the path set in .bashrc
Create simple script
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"
2.
Next put your all system variables in file /home/user/.environment_variables (any file you want)
My looks like:
export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
3.
Now you can delete your variables in .bashrc and put line
source /home/user/.environment_variables
Everything works fine :)
As pointed out in https://github.com/atom/atom/issues/7045, the environment variables can be loaded automatically, without explicit source ~/.bash_profile by using
#!/usr/bin/env bash -l
instead of
#!/bin/bash
source ~/.bash_profile
after that, in both cases, follows
exec "`dirname \"$0\"`/eclipse" $#
It works great for me, thanks for all previous work.
After setting env variables in .bash_profile.
Simply open the application through terminal!
open /Application/{path/to/app}.app