7

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
  • 2,634
  • 4
  • 19
  • 23
  • 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 Jul 10 '18 at 23:33

3 Answers3

13

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
  • 9,890
  • 3
  • 34
  • 41
  • 2
    This worked! Well, the exact command in QuickOpener was `C:\cygwin\bin\mintty /bin/sh -lc 'cd "$(cygpath "${currentFolder}")"; exec bash'` – MikeFHay May 14 '13 at 09:53
  • 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 May 22 '17 at 11:58
  • 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 May 22 '17 at 12:02
  • @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 Mar 25 '19 at 03:44
  • @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 Mar 25 '19 at 07:06
2

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
  • 31,057
  • 6
  • 55
  • 80
  • 1
    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 May 06 '13 at 15:05
0

I usually start Cygwin using the context menu with "Bash Prompt Here" (chere), and peth's answer didn't set up my environment the same as that. I looked at the registry and found that this is what "Bash Prompt Here" executes:

C:\cygwin64\bin\mintty.exe -e /bin/xhere /bin/bash.exe C:\path\to\your\directory

This works for me. It does require that chere is installed however.

Samuel
  • 131
  • 5