Page 1 of 1

Windows: ESP IDF command prompt here

Posted: Thu Jan 26, 2017 1:46 pm
by MartyMacGyver
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):

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'"
Then add the following to the end of your MSYS2 ~/.bashrc:

Code: Select all

if [[ "${OLDPWD}" != "/" ]]; then
  cd -
fi
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.

Re: Windows: ESP IDF command prompt here

Posted: Mon Jan 30, 2017 6:08 am
by ksmith9109
Spectacular tool for Windows folk that are not expert with unix....Thanks :D