Windows: ESP IDF command prompt here
Posted: Thu Jan 26, 2017 1:46 pm
Rather than starting the MSYS2 shell and then navigating to where I'm working, it's nice to just click and start a shell where I am (or in a given folder). Here's my Windows 7 registry update file (this assumes you have MSYS2 installed at C:\msys32):
Then add the following to the end of your MSYS2 ~/.bashrc:
It's a bit convoluted but it works nicely when you've got it set up.
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.
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.