Search code examples
eclipsecygwinmintty

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.


Solution

  • 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:

    1. Make sure to install chere Cygwin package;
    2. Install StartExplorer Eclipse plugin;
    3. 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:

    1. indicate to the login shells not to cd $HOME (export CHERE_INVOKING=true, which is checked for in /etc/profile);
    2. change to the directory passed as 2nd argument (cd "$2");
    3. 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.