Cygwin: Run a script in mintty/bash

2

1

Initially asked on SO.com, but I closed it. I think it better fits SU.com. Please tell me if it is also not the right place.

I want to add a context menu to a .sh file to run it in cygwin.

I tried to manipulate the default "Open Cygwin here" command:

C:\cygwin\bin\mintty.exe -e /bin/xhere /bin/bash.exe "%L"

Unfortunately, all I get is a window that closes again immediately.
Also, I am not 100% sure, what is the purpose and the meaning of the arguments of xhere.

This is working:

C:\cygwin\bin\bash.exe %1

But I'd like to have mintty as terminal window.

Final Question:
Is there a way to add a command string to be executed to the "Open Cygwin here" string?

Nippey

Posted 2014-04-14T13:08:41.527

Reputation: 161

Answers

2

Thanks to @vaz_az for keeping me motivated.

The problem with cygwin is, that it requires POSIX style paths.

This means that you have to translate the file parameter %1 that is supplied by windows. This can be done using the cygpath tool. The following code shows a 1-liner that can be used as command in regedit:

C:\cygwin\bin\mintty.exe -e /bin/bash -l -c '$(/bin/cygpath "%1")'

In the following line, there are some examples, what can be done with a 1-liner:

#Simple
C:\cygwin\bin\mintty.exe -e bash -l -c '$(cygpath "%1")'

#Fire and Forget (With 1 second delay at the end to read any messages)
C:\cygwin\bin\mintty.exe -e bash -l -c '$(cygpath "%1"); echo DONE; sleep 1'

#With logging to static file
C:\cygwin\bin\mintty.exe -l C:\cygwin\home\Nippey\cygwin.log -e /bin/bash -l -c '$(cygpath "%1")'

#With interactive shell after execution (Unfortunately the -i parameter of bash does not work together with -c, so you have to start a sub-shell)
C:\cygwin\bin\mintty.exe -e /bin/bash -l -c '$(cygpath "%1"); bash'

Nippey

Posted 2014-04-14T13:08:41.527

Reputation: 161

2$(cygpath "%1") will not work with paths that contain a space. Use $(cygpath -ms "%1") instead. – user11153 – 2015-05-20T12:13:05.780

1Nice finding. I won't pull it into my answer, because depending on how your HDD has been formatted, the old 8.3 format might be unsupported. Anyway: For me it works even without the -ms switch! This is my console then: Starting /bin/bash.exe >> xxx@xxx /cygdrive/c/Program Files I think it is a question of setting the right quotes. – Nippey – 2015-05-20T16:03:36.037

0

You should try with the following command : C:\cygwin\bin\mintty.exe -e /bin/bash -l -c '%1'.

Arnaud

Posted 2014-04-14T13:08:41.527

Reputation: 133

Thanks for your feedback. It actually didn't solve my problem, as Cygwin expects Linux "/" paths and not M$ "" paths. But you pushed my motivation to try harder! I will add a separate answer. – Nippey – 2014-05-13T08:45:53.717

To be more exact, using your answer leads to /bin/bash: C:cygwinhomeNippeytest.sh: command not found – Nippey – 2014-05-13T08:47:56.090