respect PATHEXT instead of hardcoding our own value

* support other path extensions as well (e.g. `.py` commonly used)
This commit is contained in:
David Refoua 2024-11-14 00:00:53 +03:30
parent 510178852d
commit 7ceacb63dd

View File

@ -10,6 +10,13 @@ if "%~1" == "/h" (
call :%*
)
setlocal enabledelayedexpansion
if not defined find_pathext (
set "find_pathext=!PATHEXT:;= !"
set "find_pathext=!find_pathext:.=\.!"
)
endlocal & set "find_pathext=%find_pathext%"
exit /b
:enhance_path
@ -50,7 +57,7 @@ exit /b
set "position="
)
dir "%add_path%" 2>NUL | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL
dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL
if "%ERRORLEVEL%" == "0" (
set "add_to_path=%add_path%"
@ -184,7 +191,7 @@ exit /b
set "position="
)
dir "%add_path%" 2>NUL | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL
dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL
if "%ERRORLEVEL%" == "0" (
set "add_to_path=%add_path%"