Start Cygwin from a folders context menu

My friend had a great little program, which essentially let you right click on any folder and open the command prompt there. The only program is that I never use the command line (CMD.EXE)… I use cygwin. A wonderful program that emulates Linux for windows, but also makes everything complicated!

After a short search on the web, I found a nice little discussion on a newsgroup that explained how to do it for cygwin. I just wanted to note the steps for windows XP, just so I don’t forget (If you really care… you can find steps for other versions on the discussion board).

1. Edit Registry

Start regedit.exe.

HKEY_CLASSES_ROOTDirectoryshellBashHere="Bash Here"
HKEY_CLASSES_ROOTDirectoryshellBashHerecommand="C:\WINDOWS\System32\CMD.EXE /E:4096 /c C:\cygwin\cygwin.bat %1"

Adjust the path to cygwin.bat if necessary.

Finish regedit.

You should now see the entry “Bash Here” in the context menu of a folder. However, when you use it, it will start the shell in your home directory ($HOME).

2. Edit cygwin.bat in c:/cygwin

Insert “set BASHHERE=%1” before the line with “bash…”. This Environment variable now contains the complete path of the opened folder and is availabile in the bash shell (echo $BASHHERE).

3. Edit profile

Make $BASHHERE the current directory by adding the following line to
/etc/profile or ~/.profile:

if [ "$BASHHERE" != "" ]; then
    cd $( echo $BASHHERE | tr "134" /)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s