Windows: ESP IDF command prompt here

MartyMacGyver
Posts: 56
Joined: Sun Dec 18, 2016 9:17 pm

Windows: ESP IDF command prompt here

Postby MartyMacGyver » 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):

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.

ksmith9109
Posts: 2
Joined: Sun Nov 15, 2015 6:05 am

Re: Windows: ESP IDF command prompt here

Postby ksmith9109 » Mon Jan 30, 2017 6:08 am

Spectacular tool for Windows folk that are not expert with unix....Thanks :D

Who is online

Users browsing this forum: Baidu [Spider] and 248 guests