Set app environment variables for running 3rd party apps as extensions
Kind of solution for https://github.com/zufuliu/notepad2/issues/259.
For grepWin using a launcher:
- Prepare the grepWin. Locate it in
D:\grepWin\grepWin_portable.exefor example. - Create a script
gw.bat:@start D:\grepWin\grepWin_portable.exe /content /searchpath:"%cd%" - Config the command line of grepWin editor setting to
notepad2 /g %line% %path%. Ctrl + R-->gw, search or replace.- Double click the search result will locate the line in notepad2.
For ripgrep:
- Locate
rg.exein the same directory asnotepad2. Ctrl + R-->cmd-->rg.
N2Root is in case of there is the same name files in the directory of the opened file and notepad2, it can be used as a short and unique prefix.
There is no use of N2Root and modify PATH isn't good. When integrating 3rd tools, we can find their executable from
GetProgramRealPath(), same directory as Notepad2.exe.GetModuleFileName(), same directory as symbolic link to Notepad2.exe.SearchPath()
The key logic is launching other files in the order of: dir of the opened file (current dir) --> dir of notepad2 --> systerm path.
I tried getting the dir of notepad2 dynamically, and then implement the logic. But, I did not manage it as simple as this, if dir of notepad2 is not added at the head of PATH.
Modified environment variables only have the lifetime in the current progress and its descendants. It won't be a problem.
Without N2Root, what if there is rg.bat/rg.exe/rg.js in dir of the opened file, and also in the dir of notepad2? Isn't %N2Root%\rg simpler?
Reasons to modify Path:
- The path searching order is:
current dir-->Path. And we should insertdir of notepad2between them. - CLI tools. The designed "
Ctrl + R-->cmd-->rg" won't be possible, if don't modifyPath.
delayed this until there is real usage for the changes.