Right-click a folder to get shell prompt via context menu

From Site
Jump to: navigation, search

In elevated regedt32, go to


I have added three extra keys there, one for each shell I use: Command Prompt, Cygwin, and MSYS.

Actually, the Cygwin menu entry was done by a Cygwin script, which is how I learnt about this.

For each context-menu entry on a folder, two things are needed: the text of the menu entry, and the command which will be run. In this case, the contents are all under the (Default) values of the keys.

The contents are as follows:

    Command Line
    cmd /K "cd %1"
    C:\E\ref\CygwinHere.bat %1
    MSYS rxvt
    cmd /K "set BASH_CD=%1 && C:\E\ref\MSYS_bashcd.bat"

The first one, with Command Prompt, is the simplest and self-explanatory.

The second one calls a file CygwinHere.bat which contains:

@echo off

chdir C:\cygwin\bin

rxvt -e bash --login -i -c "cd ""`cygpath -u '%1'`""; exec bash"

What happens there is that the path needs to be translated into a Cygwin path.

For one reason or another, and maybe I made a mistake somewhere, but the above did not work as nicely with MinGW/MSYS and rxvt.

So, the third context menu entry above sets an environment variable, and calls the file MSYS_bashcd.bat with the contents:

@echo off

cd C:\Programs\MSYS\1.0\bin

start %WD%rxvt -backspacekey ^H -sl 2500 -fg Navy ^
-bg LightYellow -sr -fn Courier-12 -si -sk ^
--color0 orange1 --color1 RoyalBlue3 --color2 ^
"#CCBBDD" --color3 DodgerBlue4 ^
--color4 DodgerBlue3 --color5 SkyBlue4 ^
--color6 red --color7 firebrick3 --color8 brown1 ^
--color9 sienna1 --color10 OrangeRed2 ^
--color11 coral3 --color12 DarkGoldenrod2 ^
--color13 cyan4 --color14 "#e4c70e" ^
--color15 DeepSkyBlue4 -tn msys ^
-geometry 80x25 -e "/bin/bash" ^
--login -i -c "echo 'Hi' ; bash"


(Note that the ^H after -backspacekey is actually a special character with the ASCII value 8.)

Anyway, nothing interesting happens there, except some colours get set.

The trick is that in the ~/.bashrc file, I have the following at the end:

   if [ "${BASH_CD+not_null_check}" ]; then
       echo cd "$BASH_CD";
       cd "$BASH_CD";

In other words, when the variable $BASH_CD is set, it will change directory to that path. Unlike Cygwin, MSYS doesn't care that the path is a Windows path. It can tolerate that.