Tuesday, December 26, 2006

Simplest way to add "Cygwin Prompt Here" to Windows Explorer

Just like Eric Sink, the first thing I install on my windows laptop is Cygwin and, well not Emacs anymore, gvim. I just can't image using windows so pre-mature shell to get anything done. One little problem with Cygwin is since it uses a unix like directory structure, switching back and forth between Windows Explorer and Cygwin has been a pain in the ass for a long time. Now, time to scratch the itch.

A quick Google search redirects me to Bruce Eckel's article on this same problem. It proposes two solutions but unfortunately none of them works perfectly on my environment. After hacking around, here is my solution. Different from the existing ones, this is the simplest solution I could find so far. No .bashrc, no .bat file, only one tiny .reg file. Enjoy it and see my code comments in lines.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Cmd Here]
@="Cygwin &Prompt Here"
[HKEY_CLASSES_ROOT\Folder\shell\Cmd Here\command]
@="cmd.exe /c c:\\cygwin\\bin\\bash.exe --login -c \"cd '%1'; exec /bin/bash\""


  1. Save the above text into any reg in any folder, double click it and you should be all set. (Assuming you're using the Cygwin default installation path, of course.)
  2. cmd.exe /c : launch the cmd.exe and execute the command after the /c parameter. Close the command window when the bash exits.
  3. bash.exe --login :load the user settings for the login user. -c means to execute the commands after login.
  4. cd %1; :retrieve the folder path from Windows Explorer
  5. exec /bin/bash: to open the bash environment.


Raju said...

Thanks a million! That worked for me. I would rather have the Cygwin prompt on the context menu that the CMD prompt offered by Windows Power tools.

RevRagnarok said...

Make it a /c on cmd.exe (not /k) to make it quit when done; otherwise you are stuck with a useless command prompt when you quit bash.

Alex Dong said...

rxvt here

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Cmd Here]
@="r&xvt Here"
[HKEY_CLASSES_ROOT\Folder\shell\Cmd Here\command]
@="c:\\cygwin\\bin\\rxvt.exe -bg peachpuff -sr -sl 10000 -e /usr/bin/bash --login -c \"cd '%1'; exec /bin/bash -rcfile ~/.bashrc\""

Craig McQueen said...

It seems to use the directory's short filename--e.g.
instead of
/cygdrive/c/Program\ Files

Any way to make it use long filename?