Code: Select all
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2esp]
@="&ESP IDF"
"Icon"="\"C:\\msys32\\msys2.ico\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\msys2esp\command]
@="C:\\msys32\\usr\\bin\\mintty.exe /bin/sh -lc 'cd \"$(cygpath \"%V\")\"; exec bash --login'"
[HKEY_CLASSES_ROOT\Directory\shell\msys2esp]
@="&ESP IDF"
"Icon"="\"C:\\msys32\\msys2.ico\""
[HKEY_CLASSES_ROOT\Directory\shell\msys2esp\command]
@="C:\\msys32\\usr\\bin\\mintty.exe /bin/sh -lc 'cd \"$(cygpath \"%V\")\"; exec bash --login'"
Code: Select all
if [[ "${OLDPWD}" != "/" ]]; then
cd -
fi
Why does it work? When mintty is invoked it's given two commands to process: one sets the current directory to whatever was passed in by the Windows context menu handler, and then it runs bash in login session mode... unfortunately this taked you to your home directory.
The trick is, that first chdir sets OLDPWD to the directory this was invoked with - if you used this context menu to get there. If you just clicked the shortcut, OLDPWD is set to '/'. So, if you use the usual desktop link .bashrc won't change your starting directory (home), but if you use the context menu it'll correct set it to what it was invoked with.