mirror of
https://github.com/cmderdev/cmder.git
synced 2025-06-15 22:27:51 +08:00
Fix and enhance enhance_path_recursive
This commit is contained in:
63
vendor/lib/lib_path.cmd
vendored
63
vendor/lib/lib_path.cmd
vendored
@ -51,17 +51,26 @@ exit /b
|
||||
set "position="
|
||||
)
|
||||
|
||||
dir "%add_path%" | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
set "add_to_path=%add_path%"
|
||||
) else (
|
||||
set "add_to_path="
|
||||
)
|
||||
|
||||
if "%fast_init%" == "1" (
|
||||
if "%position%" == "append" (
|
||||
set "PATH=%PATH%;%add_path%"
|
||||
set "PATH=%PATH%;%add_to_path%"
|
||||
) else (
|
||||
set "PATH=%add_path%;%PATH%"
|
||||
set "PATH=%add_to_path%;%PATH%"
|
||||
)
|
||||
goto :end_enhance_path
|
||||
) else if "add_to_path" equ "" (
|
||||
goto :end_enhance_path
|
||||
)
|
||||
|
||||
set found=0
|
||||
set "find_query=%add_path%"
|
||||
set "find_query=%add_to_path%"
|
||||
set "find_query=%find_query:\=\\%"
|
||||
set "find_query=%find_query: =\ %"
|
||||
set OLD_PATH=%PATH%
|
||||
@ -90,11 +99,11 @@ exit /b
|
||||
|
||||
if "%found%" == "0" (
|
||||
if /i "%position%" == "append" (
|
||||
%lib_console% debug_output :enhance_path "Appending '%add_path%'"
|
||||
set "PATH=%PATH%;%add_path%"
|
||||
%lib_console% debug_output :enhance_path "Appending '%add_to_path%'"
|
||||
set "PATH=%PATH%;%add_to_path%"
|
||||
) else (
|
||||
%lib_console% debug_output :enhance_path "Prepending '%add_path%'"
|
||||
set "PATH=%add_path%;%PATH%"
|
||||
%lib_console% debug_output :enhance_path "Prepending '%add_to_path%'"
|
||||
set "PATH=%add_to_path%;%PATH%"
|
||||
)
|
||||
|
||||
set found=1
|
||||
@ -150,20 +159,26 @@ exit /b
|
||||
exit 1
|
||||
)
|
||||
|
||||
if "%~2" gtr "1" (
|
||||
set "max_depth=%~2"
|
||||
) else (
|
||||
set "max_depth=1"
|
||||
)
|
||||
set "depth=%~2"
|
||||
set "max_depth=%~3"
|
||||
|
||||
if "%~3" neq "" if /i "%~3" == "append" (
|
||||
set "position=%~3"
|
||||
if "%~4" neq "" if /i "%~4" == "append" (
|
||||
set "position=%~4"
|
||||
) else (
|
||||
set "position="
|
||||
)
|
||||
|
||||
dir "%add_path%" | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL
|
||||
if "%ERRORLEVEL%" == "0" (
|
||||
set "add_to_path=%add_path%"
|
||||
) else (
|
||||
set "add_to_path="
|
||||
)
|
||||
|
||||
if "%fast_init%" == "1" (
|
||||
call :enhance_path "%add_path%" %position%
|
||||
if "%add_to_path%" neq "" (
|
||||
call :enhance_path "%add_to_path%" %position%
|
||||
)
|
||||
)
|
||||
|
||||
set "PATH=%PATH:;;=;%"
|
||||
@ -171,20 +186,22 @@ exit /b
|
||||
exit /b
|
||||
)
|
||||
|
||||
if "%depth%" == "" set depth=0
|
||||
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var - add_path=%add_path%"
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var - add_path=%add_to_path%"
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var - position=%position%"
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var - depth=%depth%"
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var - max_depth=%max_depth%"
|
||||
|
||||
if %max_depth% gtr %depth% (
|
||||
%lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_path%'"
|
||||
call :enhance_path "%add_path%" %position%
|
||||
if "%add_to_path%" neq "" (
|
||||
%lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_to_path%'"
|
||||
call :enhance_path "%add_to_path%" %position%
|
||||
)
|
||||
call :set_depth
|
||||
call :loop_depth
|
||||
)
|
||||
|
||||
set "PATH=%PATH%"
|
||||
|
||||
exit /b
|
||||
|
||||
: set_depth
|
||||
@ -192,10 +209,14 @@ exit /b
|
||||
exit /b
|
||||
|
||||
:loop_depth
|
||||
if %depth% == %max_depth% (
|
||||
exit /b
|
||||
)
|
||||
|
||||
for /d %%i in ("%add_path%\*") do (
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var BEFORE - depth=%depth%"
|
||||
%lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
|
||||
call :enhance_path_recursive "%%~fi" %max_depth% %position%
|
||||
call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position%
|
||||
%lib_console% debug_output :enhance_path_recursive "Env Var AFTER- depth=%depth%"
|
||||
)
|
||||
exit /b
|
||||
|
Reference in New Issue
Block a user