How to open cygwin & execute bash in Eclipse? - 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.

Related

error while installing python extensions " can't open file 'directory + filename': [Errno 2] No such file or directory "

I tried to install mypy extension in vs code but it keeps showing me this error below
C:\Users\Yourusername\Dev\django_project_boilerplate\env\Scripts\python.exe: can't open file 'c:UsersYourusername.vscodeextensionsms-python.python-2020.6.89148pythonFilespyvsc-run-isolated.py': [Errno 2] No such file or directory
(env)
then I realized that the terminal is removing the anti-slashes from the file location in the commande below because it's a special character
c:/Users/Yourusername/Dev/django_project_boilerplate/env/Scripts/python.exe c:\Users\Yourusername\.vscode\extensions\ms-python.python-2020.6.89148\pythonFiles\pyvsc-run-isolated.py pip install -U mypy
I got the same error when clicking the "Install ipykernel" on the pop-up window when trying to use Python Interactive mode in VS Code.
My problem was that I had git bash as my default shell while running VS Code on Windows, hence filepaths where not being processed properly.
I solved the problem by changing my Terminal's default shell:
Type: ctrl + shift + p
In the dropdown, select Terminal: Select Default Shell
In the subsequent dropdown, select Command Prompt C:\...
Try running Interactive mode once again (e.g. add # %% above a line of code and then click Run Cell)
Now click "Install ipykernel" on the pop-up window that comes up on the bottom right corner.
The installation now executed from the cmd shell without any problems, and Interactive mode worked fine.
what I did is to add an extra anti-slash and it worked fine :
c:/Users/Yourusername/Dev/django_project_boilerplate/env/Scripts/python.exe c:\\Users\\Yourusername\\.vscode\\extensions\\ms-python.python-2020.6.89148\\pythonFiles\\pyvsc-run-isolated.py pip install -U mypy
For as I also use git bash as my default terminal in windows, I used the following command:
python /c/Users/uname/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/pyvsc-run-isolated.py pip install -U black --user
Whereas I was getting error like this, before:
C:/Users/uname/AppData/Local/Programs/Python/Python38/python.exe c:\Users\uname\.vscode\extensions\ms-python.python-2021.3.680753044\pythonFiles\pyvsc-run-isolated.py pip install -U black --user
C:\Users\uname\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'c:Usersigour.vscodeextensionsms-python.python-2021.3.680753044pythonFilespyvsc-run-isolated.py': [Errno 2]
No such file or directory
As you can see it is due to the way git bash handles the file location differently, which I fixed and it worked fine alter.
Honestly, I love to see windows start following the same directory structure like other Linux system(Hope some day this will become true).
Change your vs code's terminal back to Default Shell > Command Prompt C:\Windows...
The error is due to PATH conflict while using git bash as default terminal on VS Code.

How to change default eclipse shell interpreter?

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

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.

Configuring Eclipse for ROS

I am new to Linux. I am trying to develop ROS application using eclipse. I don't understand the below which is provided in ROS website. Can you explain this in more simple way, So that I can configure my eclipse after downloading from eclipse.org.
Reusing your shell's environment
For building and running ROS programs from inside IDEs, the ROS
enviroment has to be set up. All IDEs might have a config for that,
but running your IDE from your ROS-sourced shell should be the easiest
way, avoiding inconsistency.
Likewise, you can enhance your IDE's launcher icon to load your shells
environment. E.g., replace its command eclipse with
bash -i -c "eclipse". This will make bash source
~/.bashrc, in which ROS has to
be sourced and parameterized, and start that IDE.
use following commands:
cd <your_catkin_workspace>
catkin_make --force-cmake -G"Eclipse CDT4 - Unix Makefiles"
cd build
cmake ../src -DCMAKE_BUILD_TYPE=Debug
now you can import your project to eclipse
after that you can create a desktop application entry for eclispe:
sudo vim /usr/share/applications/eclipse.desktop
[Desktop Entry]
Type=Application
Terminal=false
Icon=<path_to_your_eclipse_dir>/icon.xpm
Exec=bash -i -c "source /opt/ros/hydro/setup.bash && source $HOME/workspace/<your_catkin_workspace>/devel/setup.bash && <path_to_your_eclipse_dir>/eclipse"
Comment=IDE
Name=eclipse
Comment=IDE
It seems that a wiki was published about this subject here
Put simply, the lines you listed are suggesting you run your IDE (eclipse) from a terminal which has already been sourced. So for instance, if you have a package called mypackage, you might type in a terminal:
cd ~/mypackage
source devel/setup.bash
eclipse
The first line is just however you get to your package, the second line sets up environmental variables for you (like changing your PATH), then you can run eclipse with all of those already setup so you don't have to configure your package in eclipse 100% manually.

Run command through External Tools Configuration in Eclipse on Mac

I'm try to execute the following string of commands through a an External Tools Configuration in Eclipse (it basically deploys a build to a server and touches the server's plan file, causing the server to update itself with the new build):
mvn -P virgo package -o -Dmaven.test.skip=true && touch ${env_var:SERVER_HOME}/pickup/{project_name}.plan
On Windows, I was able to pass this string (with slight modifications) to cmd.exe using its /c argument and see the output in Eclipse's Console.
How can I get this behavior on Mac?
UPDATE
Another way of phrasing the question is, how can one feed an argument to Terminal to be execute (i.e., Terminal.app -argument "mvn -P virgo package -o -Dmaven.test.skip=true && touch ${env_var:SERVER_HOME}/pickup/{project_name}.plan")?
Another possibility would be to use a shell script, but I don't have experience with them.