2

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?

2 Answers 2

3

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'
2
  • 3
    $(cygpath "%1") will not work with paths that contain a space. Use $(cygpath -ms "%1") instead.
    – user11153
    May 20, 2015 at 12:13
  • 1
    Nice 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
    May 20, 2015 at 16:03
0

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

2
  • 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
    May 13, 2014 at 8:45
  • To be more exact, using your answer leads to /bin/bash: C:cygwinhomeNippeytest.sh: command not found
    – Nippey
    May 13, 2014 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .