How to open a Cygwin shell at a specific directory from Netbeans?

5

3

I've tried using QuickOpener with the command:

C:\cygwin\bin\mintty.exe -e cd `cygpath "${currentFolder}"`

but it just opens a window saying: cd: No such file or directory.

MikeFHay

Posted 2013-05-06T13:46:45.133

Reputation: 2 334

The best way to avoid Cygwin / Wn path incompatibilities is by changing current directory inside Netbeans to whatever you need. mintty respects current directory. – gavenkoa – 2018-07-10T23:33:34.663

Answers

12

mintty can't directly call cd because that's a builtin command of the respective shell. What you really want is to start a shell in the correct directory.

I don't know about NetBeans or QuickOpener, but provided currentFolder contains an absolute Windows path, the following should work:

C:\cygwin\bin\mintty /bin/sh -lc 'cd "$(cygpath "$currentFolder")"; exec bash'

This runs a proper login shell that changes directory and then replaces itself with bash.

peth

Posted 2013-05-06T13:46:45.133

Reputation: 7 990

There two-paired nested quotation mark doesn't work for me: windows: mintty /bin/sh -lc 'cd "$(cygpath "C:\Program Files\ ")"; exec bash' Error shows: /bin/sh: line 0: cd: /cygdrive/c/Program Files/ : No such file or directory – Marslo – 2017-05-22T11:58:22.563

If removed the outermost layer of double quotes, mintty /bin/sh -lc 'cd $(cygpath "C:\Program Files\ "); exec bash' -> Error: /bin/sh: line 0: cd: too many arguments; If removed the inner layer double quotes, mintty /bin/sh -lc 'cd "$(cygpath C:\Program Files\ )"; exec bash' -> Error: /bin/sh: line 0: cd: /cygdrive/c/Program Files/ : No such file or directory – Marslo – 2017-05-22T12:02:23.437

@Marslo As sh was telling you, that's because there is no file or directory called " " (only a space) that it's expecting because of your test string. You can't just put any literal in there and expect it to work, you have to mind backslash escapes in the quotes. Try C:\\Program Files to test, and it should work. – peth – 2019-03-25T03:44:43.020

@peth, thanks for your comments :). I'm using Mac now. I will let you know if I got chance to touch windows :). Thanks again. – Marslo – 2019-03-25T07:06:18.317

2This worked! Well, the exact command in QuickOpener was C:\cygwin\bin\mintty /bin/sh -lc 'cd "$(cygpath "${currentFolder}")"; exec bash' – MikeFHay – 2013-05-14T09:53:13.847

1

Not quite you asked for, but Cygwin comes with chere which sets up a context menu in Windows Explorer.

This may be a decent substitute for what you ask, and you might be able to check the mechanism that chere uses to fix your issue.

Rich Homolka

Posted 2013-05-06T13:46:45.133

Reputation: 27 121

chere is great, and I do use it. You're right, a solution probably could be reverse-engineered from chere, might be worth rummaging through the registry to find out what it does, or just looking up the source code. – MikeFHay – 2013-05-06T15:05:22.703