Skip to content

Commit f461904

Browse files
authored
Merge pull request #3034 from cmderdev/pr/lib_path
Improve path enhancement handling in lib_path.cmd
2 parents 13904e4 + f6eb7aa commit f461904

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

vendor/lib/lib_path.cmd

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ exit /b
9191

9292
if /i "!position!" == "append" (
9393
if "!found!" == "0" (
94-
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$"
94+
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!$"
9595
call :set_found
9696
)
9797
%print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!"
9898
) else (
9999
if "!found!" == "0" (
100-
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;"
100+
echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:"^!find_query!;"
101101
call :set_found
102102
)
103103
%print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!"
@@ -194,13 +194,28 @@ exit /b
194194
exit /b 1
195195
)
196196

197+
rem Parse arguments robustly:
198+
rem Accept either public form: "[dir_path]" [max_depth] [append]
199+
rem or internal recursive form: "[dir_path]" [depth] [max_depth] [append]
197200
set "depth=%~2"
198201
set "max_depth=%~3"
202+
set "position="
199203

200-
if "%~4" neq "" if /i "%~4" == "append" (
201-
set "position=%~4"
202-
) else (
203-
set "position="
204+
if /i "%~4" == "append" set "position=append"
205+
if /i "%~3" == "append" (
206+
set "position=append"
207+
set "max_depth="
208+
)
209+
210+
if not defined depth set "depth=0"
211+
if not defined max_depth (
212+
if defined depth (
213+
rem If only one numeric argument provided, treat it as max_depth
214+
set "max_depth=%depth%"
215+
set "depth=0"
216+
) else (
217+
set "max_depth=1"
218+
)
204219
)
205220

206221
dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL
@@ -244,8 +259,6 @@ exit /b
244259
call :loop_depth
245260
)
246261

247-
set "PATH=%PATH%"
248-
249262
exit /b
250263

251264
:set_depth

0 commit comments

Comments
 (0)