Over a million developers have joined DZone.

Starting Cygwin Bash From Windows Explorer

DZone's Guide to

Starting Cygwin Bash From Windows Explorer

· ·
Free Resource
Want to launch a bash shell in any directory using the Windows Explorer context menu?  This is how I did it, tweaking the basic method described here.  This should work even for paths that have spaces or for UNC paths.

1. Edit Registry
- Start regedit.exe.
- Add these key/values:
HKEY_CLASSES_ROOT\Directory\shell\BashHere=bash here
HKEY_CLASSES_ROOT\Directory\shell\BashHere\command=cmd.exe /c C:\cygwin\cygwin.bat "%1"

Note the quotation marks around "%1".
Please adjust the path to cygwin.bat if necessary.

2. Edit cygwin.bat in c:/cygwin

This batch starts the bash shell with the last command line "bash...".
Insert set BASHHERE=%1 the line before.

This Environment variable now contains the complete path of the opened
folder and is available in the bash shell (echo $BASHHERE).

3. Edit profile 

Make $BASHHERE the current directory by adding the following line to
/etc/profile or ~/.profile. (I'd replace your line cd "${HOME}" with the following):

  if [ "$BASHHERE" != "" ]; then
    cd "$(cygpath -u "$(echo $BASHHERE | tr -d "\042")")"
    cd "${HOME}"

The "tr -d" deletes enclosing quotes, which cygpath can't deal with for some reason when embedded in $BASHHERE.  Maybe there's a simpler way, but this way worked for me.

(For UNC paths, cmd.exe complains when you launch cygwin.bat, but it dutifully passes on the argument.)

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}