notepad4 icon indicating copy to clipboard operation
notepad4 copied to clipboard

Set app environment variables for running 3rd party apps as extensions

Open lifenjoiner opened this issue 1 year ago • 4 comments

Kind of solution for https://github.com/zufuliu/notepad2/issues/259.

For grepWin using a launcher:

  1. Prepare the grepWin. Locate it in D:\grepWin\grepWin_portable.exe for example.
  2. Create a script gw.bat:
    @start D:\grepWin\grepWin_portable.exe /content /searchpath:"%cd%"
    
  3. Config the command line of grepWin editor setting to notepad2 /g %line% %path%.
  4. Ctrl + R --> gw, search or replace.
  5. Double click the search result will locate the line in notepad2.

For ripgrep:

  1. Locate rg.exe in the same directory as notepad2.
  2. 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.

lifenjoiner avatar Jan 23 '24 11:01 lifenjoiner

There is no use of N2Root and modify PATH isn't good. When integrating 3rd tools, we can find their executable from

  1. GetProgramRealPath(), same directory as Notepad2.exe.
  2. GetModuleFileName(), same directory as symbolic link to Notepad2.exe.
  3. SearchPath()

zufuliu avatar Jan 24 '24 12:01 zufuliu

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?

lifenjoiner avatar Jan 24 '24 13:01 lifenjoiner

Reasons to modify Path:

  1. The path searching order is: current dir --> Path. And we should insert dir of notepad2 between them.
  2. CLI tools. The designed "Ctrl + R --> cmd --> rg" won't be possible, if don't modify Path.

lifenjoiner avatar Jan 24 '24 14:01 lifenjoiner

delayed this until there is real usage for the changes.

zufuliu avatar Jan 25 '24 01:01 zufuliu