diff --git a/vendor/lib/lib_base.cmd b/vendor/lib/lib_base.cmd index 46c444b..39371c7 100644 --- a/vendor/lib/lib_base.cmd +++ b/vendor/lib/lib_base.cmd @@ -1,127 +1,127 @@ -@echo off - -set lib_base=call "%~dp0lib_base.cmd" - -if "%~1" == "/h" ( - %lib_base% help "%~0" -) else if "%~1" neq "" ( - call :%* -) - -exit /b - -:::=============================================================================== -:::help - shows all sub routines in a .bat/.cmd file with documentation -:::. -:::include: -:::. -::: call "lib_base.cmd" -:::. -:::usage: -:::. -::: %lib_base% help "file" -:::. -:::options: -:::. -::: file full path to file containing lib_routines to display -:::------------------------------------------------------------------------------- - -:help - for /f "tokens=* delims=:" %%a in ('%WINDIR%\System32\findstr /i /r "^:::" "%~1"') do ( - if "%%a"=="." ( - echo. - ) else if /i "%%a" == "usage" ( - echo %%a: - ) else if /i "%%a" == "options" ( - echo %%a: - ) else if not "%%a" == "" ( - echo %%a - ) - ) - - pause - exit /b - -:::=============================================================================== -:::cmder_shell - Initializes the Cmder shell environment variables -:::. -:::description: -:::. -::: This routine sets up the Cmder shell environment by detecting the -::: command shell and initializing related variables. -:::. -:::include: -:::. -::: call "lib_base.cmd" -:::. -:::usage: -:::. -::: %lib_base% cmder_shell -:::------------------------------------------------------------------------------- - -:cmder_shell - call :detect_comspec %ComSpec% - exit /b - -:::=============================================================================== -:::detect_comspec - Detects the command shell being used::: -:::. -:::description: -:::. -::: This function sets the CMDER_SHELL variable to the name of the -::: detected command shell. It also initializes the CMDER_CLINK and -::: CMDER_ALIASES variables if they are not already defined. -:::. -:::include: -:::. -::: call "lib_base.cmd" -:::. -:::usage: -:::. -::: %lib_base% detect_comspec %ComSpec% -:::------------------------------------------------------------------------------- - -:detect_comspec - set CMDER_SHELL=%~n1 - if not defined CMDER_CLINK ( - set CMDER_CLINK=1 - ) - if not defined CMDER_ALIASES ( - set CMDER_ALIASES=1 - ) - exit /b - -:::=============================================================================== -:::update_legacy_aliases - Updates the legacy alias definitions in the user_aliases file -:::. -:::description: -:::. -::: This function checks if the user_aliases file contains the marker -::: ";= Add aliases below here". If the marker is not found, it creates -::: an initial user_aliases store by copying the default user_aliases file -::: from the CMDER_ROOT directory. If the CMDER_USER_CONFIG environment -::: variable is defined, it creates a backup of the existing user_aliases -::: file before copying the default file. -:::. -:::include: -:::. -::: call "lib_base.cmd" -:::. -:::usage: -:::. -::: %lib_base% update_legacy_aliases -:::------------------------------------------------------------------------------- - -:update_legacy_aliases - type "%user_aliases%" | %WINDIR%\System32\findstr /i ";= Add aliases below here" >nul - if "%errorlevel%" == "1" ( - echo Creating initial user_aliases store in "%user_aliases%"... - if defined CMDER_USER_CONFIG ( - copy "%user_aliases%" "%user_aliases%.old_format" - copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%" - ) else ( - copy "%user_aliases%" "%user_aliases%.old_format" - copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%" - ) - ) - exit /b +@echo off + +set lib_base=call "%~dp0lib_base.cmd" + +if "%~1" == "/h" ( + %lib_base% help "%~0" +) else if "%~1" neq "" ( + call :%* +) + +exit /b + +:::=============================================================================== +:::help - shows all sub routines in a .bat/.cmd file with documentation +:::. +:::include: +:::. +::: call "lib_base.cmd" +:::. +:::usage: +:::. +::: %lib_base% help "file" +:::. +:::options: +:::. +::: file full path to file containing lib_routines to display +:::------------------------------------------------------------------------------- + +:help + for /f "tokens=* delims=:" %%a in ('%WINDIR%\System32\findstr /i /r "^:::" "%~1"') do ( + if "%%a"=="." ( + echo. + ) else if /i "%%a" == "usage" ( + echo %%a: + ) else if /i "%%a" == "options" ( + echo %%a: + ) else if not "%%a" == "" ( + echo %%a + ) + ) + + pause + exit /b + +:::=============================================================================== +:::cmder_shell - Initializes the Cmder shell environment variables +:::. +:::description: +:::. +::: This routine sets up the Cmder shell environment by detecting the +::: command shell and initializing related variables. +:::. +:::include: +:::. +::: call "lib_base.cmd" +:::. +:::usage: +:::. +::: %lib_base% cmder_shell +:::------------------------------------------------------------------------------- + +:cmder_shell + call :detect_comspec %ComSpec% + exit /b + +:::=============================================================================== +:::detect_comspec - Detects the command shell being used::: +:::. +:::description: +:::. +::: This function sets the CMDER_SHELL variable to the name of the +::: detected command shell. It also initializes the CMDER_CLINK and +::: CMDER_ALIASES variables if they are not already defined. +:::. +:::include: +:::. +::: call "lib_base.cmd" +:::. +:::usage: +:::. +::: %lib_base% detect_comspec %ComSpec% +:::------------------------------------------------------------------------------- + +:detect_comspec + set CMDER_SHELL=%~n1 + if not defined CMDER_CLINK ( + set CMDER_CLINK=1 + ) + if not defined CMDER_ALIASES ( + set CMDER_ALIASES=1 + ) + exit /b + +:::=============================================================================== +:::update_legacy_aliases - Updates the legacy alias definitions in the user_aliases file +:::. +:::description: +:::. +::: This function checks if the user_aliases file contains the marker +::: ";= Add aliases below here". If the marker is not found, it creates +::: an initial user_aliases store by copying the default user_aliases file +::: from the CMDER_ROOT directory. If the CMDER_USER_CONFIG environment +::: variable is defined, it creates a backup of the existing user_aliases +::: file before copying the default file. +:::. +:::include: +:::. +::: call "lib_base.cmd" +:::. +:::usage: +:::. +::: %lib_base% update_legacy_aliases +:::------------------------------------------------------------------------------- + +:update_legacy_aliases + type "%user_aliases%" | %WINDIR%\System32\findstr /i ";= Add aliases below here" >nul + if "%errorlevel%" == "1" ( + echo Creating initial user_aliases store in "%user_aliases%"... + if defined CMDER_USER_CONFIG ( + copy "%user_aliases%" "%user_aliases%.old_format" + copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%" + ) else ( + copy "%user_aliases%" "%user_aliases%.old_format" + copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%" + ) + ) + exit /b diff --git a/vendor/lib/lib_console.cmd b/vendor/lib/lib_console.cmd index 88ddd8d..600655f 100644 --- a/vendor/lib/lib_console.cmd +++ b/vendor/lib/lib_console.cmd @@ -1,107 +1,107 @@ -@echo off - -call "%~dp0lib_base.cmd" -set lib_console=call "%~dp0lib_console.cmd" -set ESC= - -:: Much faster than using "%lib_console% debug_output ..." etc. -set print_debug=if %debug_output% gtr 0 %lib_console% debug_output -set print_verbose=if %verbose_output% gtr 0 %lib_console% verbose_output -set print_warning=if %verbose_output% gtr 0 %lib_console% show_warning -set print_error=%lib_console% show_error - -if %fast_init% gtr %verbose_output% if %fast_init% gtr %debug_output% exit /b - -if "%~1" == "/h" ( - %lib_base% help "%~0" -) else if "%~1" neq "" ( - call :%* -) - -exit /b - -:debug_output -:::=============================================================================== -:::debug_output - Output a debug message to the console. -:::. -:::include: -:::. -::: call "lib_console.cmd" -:::. -:::usage: -:::. -::: %lib_console% debug_output [caller] [message] -:::. -:::required: -:::. -::: [caller] Script/sub routine name calling debug_output -:::. -::: [message] Message text to display. -:::. -:::------------------------------------------------------------------------------- - - if %debug_output% gtr 0 echo %time% DEBUG(%~1): %~2 & echo. - exit /b - -:verbose_output -:::=============================================================================== -:::verbose_output - Output a debug message to the console. -:::. -:::include: -:::. -::: call "$0" -:::. -:::usage: -:::. -::: %lib_console% verbose_output "[message]" -:::. -:::required: -:::. -::: [message] Message text to display. -:::. -:::------------------------------------------------------------------------------- - - if %verbose_output% gtr 0 echo %~1 - exit /b - -:show_error -:::=============================================================================== -:::show_error - Output an error message to the console. -:::. -:::include: -:::. -::: call "$0" -:::. -:::usage: -:::. -::: %lib_console% show_error "[message]" -:::. -:::required: -:::. -::: [message] Message text to display. -:::. -:::------------------------------------------------------------------------------- - - echo %ESC%[91;1mERROR:%ESC%[0m %~1 - exit /b - -:show_warning -:::=============================================================================== -:::show_warning - Output a warning message to the console. -:::. -:::include: -:::. -::: call "$0" -:::. -:::usage: -:::. -::: %lib_console% show_warning "[message]" -:::. -:::required: -:::. -::: [message] Message text to display. -:::. -:::------------------------------------------------------------------------------- - - echo %ESC%[93;1mWARNING:%ESC%[0m %~1 - exit /b +@echo off + +call "%~dp0lib_base.cmd" +set lib_console=call "%~dp0lib_console.cmd" +set ESC= + +:: Much faster than using "%lib_console% debug_output ..." etc. +set print_debug=if %debug_output% gtr 0 %lib_console% debug_output +set print_verbose=if %verbose_output% gtr 0 %lib_console% verbose_output +set print_warning=if %verbose_output% gtr 0 %lib_console% show_warning +set print_error=%lib_console% show_error + +if %fast_init% gtr %verbose_output% if %fast_init% gtr %debug_output% exit /b + +if "%~1" == "/h" ( + %lib_base% help "%~0" +) else if "%~1" neq "" ( + call :%* +) + +exit /b + +:debug_output +:::=============================================================================== +:::debug_output - Output a debug message to the console. +:::. +:::include: +:::. +::: call "lib_console.cmd" +:::. +:::usage: +:::. +::: %lib_console% debug_output [caller] [message] +:::. +:::required: +:::. +::: [caller] Script/sub routine name calling debug_output +:::. +::: [message] Message text to display. +:::. +:::------------------------------------------------------------------------------- + + if %debug_output% gtr 0 echo %time% DEBUG(%~1): %~2 & echo. + exit /b + +:verbose_output +:::=============================================================================== +:::verbose_output - Output a debug message to the console. +:::. +:::include: +:::. +::: call "$0" +:::. +:::usage: +:::. +::: %lib_console% verbose_output "[message]" +:::. +:::required: +:::. +::: [message] Message text to display. +:::. +:::------------------------------------------------------------------------------- + + if %verbose_output% gtr 0 echo %~1 + exit /b + +:show_error +:::=============================================================================== +:::show_error - Output an error message to the console. +:::. +:::include: +:::. +::: call "$0" +:::. +:::usage: +:::. +::: %lib_console% show_error "[message]" +:::. +:::required: +:::. +::: [message] Message text to display. +:::. +:::------------------------------------------------------------------------------- + + echo %ESC%[91;1mERROR:%ESC%[0m %~1 + exit /b + +:show_warning +:::=============================================================================== +:::show_warning - Output a warning message to the console. +:::. +:::include: +:::. +::: call "$0" +:::. +:::usage: +:::. +::: %lib_console% show_warning "[message]" +:::. +:::required: +:::. +::: [message] Message text to display. +:::. +:::------------------------------------------------------------------------------- + + echo %ESC%[93;1mWARNING:%ESC%[0m %~1 + exit /b diff --git a/vendor/lib/lib_path.cmd b/vendor/lib/lib_path.cmd index ee493b7..7edb2f5 100644 --- a/vendor/lib/lib_path.cmd +++ b/vendor/lib/lib_path.cmd @@ -1,253 +1,253 @@ -@echo off - -call "%~dp0lib_base.cmd" -call "%~dp0lib_console.cmd" -set lib_path=call "%~dp0lib_path.cmd" - -if "%~1" == "/h" ( - %lib_base% help "%~0" -) else if "%~1" neq "" ( - 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 -:::=============================================================================== -:::enhance_path - Add a directory to the path env variable if required. -::: -:::include: -::: -::: call "lib_path.cmd" -::: -:::usage: -::: -::: %lib_path% enhance_path "[dir_path]" [append] -::: -:::required: -::: -::: [dir_path] Fully qualified directory path. Ex: "c:\bin" -::: -:::options: -::: -::: append Append to the path env variable rather than pre-pend. -::: -::: -:::output: -::: -::: path Sets the path env variable if required. -:::------------------------------------------------------------------------------- - if "%~1" neq "" ( - set "add_path=%~1" - ) else ( - %print_error% "You must specify a directory to add to the path!" - exit /b 1 - ) - - if "%~2" neq "" if /i "%~2" == "append" ( - set "position=%~2" - ) else ( - set "position=" - ) - - dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >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_to_path%" - ) else ( - 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_to_path%" - set "find_query=%find_query:\=\\%" - set "find_query=%find_query: =\ %" - set "OLD_PATH=%PATH%" - - setlocal enabledelayedexpansion - if "!found!" == "0" ( - echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!;" - call :set_found - ) - %print_debug% :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!" - - if /i "!position!" == "append" ( - if "!found!" == "0" ( - echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$" - call :set_found - ) - %print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!" - ) else ( - if "!found!" == "0" ( - echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;" - call :set_found - ) - %print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!" - ) - endlocal & set found=%found% - - if "%found%" == "0" ( - if /i "%position%" == "append" ( - %print_debug% :enhance_path "Appending '%add_to_path%'" - set "PATH=%PATH%;%add_to_path%" - ) else ( - %print_debug% :enhance_path "Prepending '%add_to_path%'" - set "PATH=%add_to_path%;%PATH%" - ) - - set found=1 - ) - - :end_enhance_path - set "PATH=%PATH:;;=;%" - - REM echo %PATH%|wc -c - if "%fast_init%" == "1" exit /b - - if not "%OLD_PATH:~0,3000%" == "%OLD_PATH:~0,3001%" goto :toolong - if not "%OLD_PATH%" == "%PATH%" goto :changed - exit /b - - :toolong - set "_rand=%RANDOM%" - if exist "%temp%\%_rand%_cmder_lib_pathA" del "%temp%\%_rand%_cmder_lib_pathA" 2>nul 1>nul - if exist "%temp%\%_rand%_cmder_lib_pathB" del "%temp%\%_rand%_cmder_lib_pathB" 2>nul 1>nul - if exist "%temp%\%_rand%_cmder_lib_pathA" goto :toolong - if exist "%temp%\%_rand%_cmder_lib_pathB" goto :toolong - echo "%OLD_PATH%">"%temp%\%_rand%_cmder_lib_pathA" - if errorlevel 1 ( if exist "%temp%\%_rand%_cmder_lib_pathA" del "%temp%\%_rand%_cmder_lib_pathA" & goto :toolong ) - echo "%PATH%">"%temp%\%_rand%_cmder_lib_pathB" - if errorlevel 1 ( if exist "%temp%\%_rand%_cmder_lib_pathA" del "%temp%\%_rand%_cmder_lib_pathA" & if exist "%temp%\%_cmder_lib_pathB" del "%temp%\%_rand%_cmder_lib_pathB" & goto :toolong ) - fc /b "%temp%\%_rand%_cmder_lib_pathA" "%temp%\%_rand%_cmder_lib_pathB" 2>nul 1>nul - if errorlevel 1 ( del "%temp%\%_rand%_cmder_lib_pathA" & del "%temp%\%_rand%_cmder_lib_pathB" & set "_rand=" & goto :changed ) - del "%temp%\%_rand%_cmder_lib_pathA" & del "%temp%\%_rand%_cmder_lib_pathB" & set "_rand=" - exit /b - - :changed - %print_debug% :enhance_path "END Env Var - PATH=%PATH%" - %print_debug% :enhance_path "Env Var %find_query% - found=%found%" - exit /b - - exit /b - -:set_found - if "%ERRORLEVEL%" == "0" ( - set found=1 - ) - - exit /b - -:enhance_path_recursive -:::=============================================================================== -:::enhance_path_recursive - Add a directory and subs to the path env variable if -::: required. -:::. -:::include: -:::. -::: call "$0" -:::. -:::usage: -:::. -::: call "%~DP0lib_path" enhance_path_recursive "[dir_path]" [max_depth] [append] -:::. -:::required: -:::. -::: [dir_path] Fully qualified directory path. Ex: "c:\bin" -:::. -:::options: -:::. -::: [max_depth] Max recursion depth. Default: 1 -:::. -::: append Append instead to path env variable rather than pre-pend. -:::. -:::output: -:::. -::: path Sets the path env variable if required. -:::------------------------------------------------------------------------------- - if "%~1" neq "" ( - set "add_path=%~1" - ) else ( - %print_error% "You must specify a directory to add to the path!" - exit /b 1 - ) - - set "depth=%~2" - set "max_depth=%~3" - - if "%~4" neq "" if /i "%~4" == "append" ( - set "position=%~4" - ) else ( - set "position=" - ) - - dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL - - if "%ERRORLEVEL%" == "0" ( - set "add_to_path=%add_path%" - ) else ( - set "add_to_path=" - ) - - if "%fast_init%" == "1" ( - if "%add_to_path%" neq "" ( - call :enhance_path "%add_to_path%" %position% - ) - ) - - set "PATH=%PATH:;;=;%" - if "%fast_init%" == "1" ( - exit /b - ) - - %print_debug% :enhance_path_recursive "Env Var - add_path=%add_to_path%" - %print_debug% :enhance_path_recursive "Env Var - position=%position%" - %print_debug% :enhance_path_recursive "Env Var - depth=%depth%" - %print_debug% :enhance_path_recursive "Env Var - max_depth=%max_depth%" - - if %max_depth% gtr %depth% ( - if "%add_to_path%" neq "" ( - %print_debug% :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 - set /a "depth=%depth%+1" - exit /b - -:loop_depth - if %depth% == %max_depth% ( - exit /b - ) - - for /d %%i in ("%add_path%\*") do ( - %print_debug% :enhance_path_recursive "Env Var BEFORE - depth=%depth%" - %print_debug% :enhance_path_recursive "Found Subdirectory - '%%~fi'" - call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position% - %print_debug% :enhance_path_recursive "Env Var AFTER- depth=%depth%" - ) - exit /b +@echo off + +call "%~dp0lib_base.cmd" +call "%~dp0lib_console.cmd" +set lib_path=call "%~dp0lib_path.cmd" + +if "%~1" == "/h" ( + %lib_base% help "%~0" +) else if "%~1" neq "" ( + 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 +:::=============================================================================== +:::enhance_path - Add a directory to the path env variable if required. +::: +:::include: +::: +::: call "lib_path.cmd" +::: +:::usage: +::: +::: %lib_path% enhance_path "[dir_path]" [append] +::: +:::required: +::: +::: [dir_path] Fully qualified directory path. Ex: "c:\bin" +::: +:::options: +::: +::: append Append to the path env variable rather than pre-pend. +::: +::: +:::output: +::: +::: path Sets the path env variable if required. +:::------------------------------------------------------------------------------- + if "%~1" neq "" ( + set "add_path=%~1" + ) else ( + %print_error% "You must specify a directory to add to the path!" + exit /b 1 + ) + + if "%~2" neq "" if /i "%~2" == "append" ( + set "position=%~2" + ) else ( + set "position=" + ) + + dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >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_to_path%" + ) else ( + 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_to_path%" + set "find_query=%find_query:\=\\%" + set "find_query=%find_query: =\ %" + set "OLD_PATH=%PATH%" + + setlocal enabledelayedexpansion + if "!found!" == "0" ( + echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!;" + call :set_found + ) + %print_debug% :enhance_path "Env Var INSIDE PATH !find_query! - found=!found!" + + if /i "!position!" == "append" ( + if "!found!" == "0" ( + echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:";!find_query!\"$" + call :set_found + ) + %print_debug% :enhance_path "Env Var END PATH !find_query! - found=!found!" + ) else ( + if "!found!" == "0" ( + echo "!PATH!"|!WINDIR!\System32\findstr >nul /I /R /C:"^\"!find_query!;" + call :set_found + ) + %print_debug% :enhance_path "Env Var BEGIN PATH !find_query! - found=!found!" + ) + endlocal & set found=%found% + + if "%found%" == "0" ( + if /i "%position%" == "append" ( + %print_debug% :enhance_path "Appending '%add_to_path%'" + set "PATH=%PATH%;%add_to_path%" + ) else ( + %print_debug% :enhance_path "Prepending '%add_to_path%'" + set "PATH=%add_to_path%;%PATH%" + ) + + set found=1 + ) + + :end_enhance_path + set "PATH=%PATH:;;=;%" + + REM echo %PATH%|wc -c + if "%fast_init%" == "1" exit /b + + if not "%OLD_PATH:~0,3000%" == "%OLD_PATH:~0,3001%" goto :toolong + if not "%OLD_PATH%" == "%PATH%" goto :changed + exit /b + + :toolong + set "_rand=%RANDOM%" + if exist "%temp%\%_rand%_cmder_lib_pathA" del "%temp%\%_rand%_cmder_lib_pathA" 2>nul 1>nul + if exist "%temp%\%_rand%_cmder_lib_pathB" del "%temp%\%_rand%_cmder_lib_pathB" 2>nul 1>nul + if exist "%temp%\%_rand%_cmder_lib_pathA" goto :toolong + if exist "%temp%\%_rand%_cmder_lib_pathB" goto :toolong + echo "%OLD_PATH%">"%temp%\%_rand%_cmder_lib_pathA" + if errorlevel 1 ( if exist "%temp%\%_rand%_cmder_lib_pathA" del "%temp%\%_rand%_cmder_lib_pathA" & goto :toolong ) + echo "%PATH%">"%temp%\%_rand%_cmder_lib_pathB" + if errorlevel 1 ( if exist "%temp%\%_rand%_cmder_lib_pathA" del "%temp%\%_rand%_cmder_lib_pathA" & if exist "%temp%\%_cmder_lib_pathB" del "%temp%\%_rand%_cmder_lib_pathB" & goto :toolong ) + fc /b "%temp%\%_rand%_cmder_lib_pathA" "%temp%\%_rand%_cmder_lib_pathB" 2>nul 1>nul + if errorlevel 1 ( del "%temp%\%_rand%_cmder_lib_pathA" & del "%temp%\%_rand%_cmder_lib_pathB" & set "_rand=" & goto :changed ) + del "%temp%\%_rand%_cmder_lib_pathA" & del "%temp%\%_rand%_cmder_lib_pathB" & set "_rand=" + exit /b + + :changed + %print_debug% :enhance_path "END Env Var - PATH=%PATH%" + %print_debug% :enhance_path "Env Var %find_query% - found=%found%" + exit /b + + exit /b + +:set_found + if "%ERRORLEVEL%" == "0" ( + set found=1 + ) + + exit /b + +:enhance_path_recursive +:::=============================================================================== +:::enhance_path_recursive - Add a directory and subs to the path env variable if +::: required. +:::. +:::include: +:::. +::: call "$0" +:::. +:::usage: +:::. +::: call "%~DP0lib_path" enhance_path_recursive "[dir_path]" [max_depth] [append] +:::. +:::required: +:::. +::: [dir_path] Fully qualified directory path. Ex: "c:\bin" +:::. +:::options: +:::. +::: [max_depth] Max recursion depth. Default: 1 +:::. +::: append Append instead to path env variable rather than pre-pend. +:::. +:::output: +:::. +::: path Sets the path env variable if required. +:::------------------------------------------------------------------------------- + if "%~1" neq "" ( + set "add_path=%~1" + ) else ( + %print_error% "You must specify a directory to add to the path!" + exit /b 1 + ) + + set "depth=%~2" + set "max_depth=%~3" + + if "%~4" neq "" if /i "%~4" == "append" ( + set "position=%~4" + ) else ( + set "position=" + ) + + dir "%add_path%" 2>NUL | findstr -i -e "%find_pathext%" >NUL + + if "%ERRORLEVEL%" == "0" ( + set "add_to_path=%add_path%" + ) else ( + set "add_to_path=" + ) + + if "%fast_init%" == "1" ( + if "%add_to_path%" neq "" ( + call :enhance_path "%add_to_path%" %position% + ) + ) + + set "PATH=%PATH:;;=;%" + if "%fast_init%" == "1" ( + exit /b + ) + + %print_debug% :enhance_path_recursive "Env Var - add_path=%add_to_path%" + %print_debug% :enhance_path_recursive "Env Var - position=%position%" + %print_debug% :enhance_path_recursive "Env Var - depth=%depth%" + %print_debug% :enhance_path_recursive "Env Var - max_depth=%max_depth%" + + if %max_depth% gtr %depth% ( + if "%add_to_path%" neq "" ( + %print_debug% :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 + set /a "depth=%depth%+1" + exit /b + +:loop_depth + if %depth% == %max_depth% ( + exit /b + ) + + for /d %%i in ("%add_path%\*") do ( + %print_debug% :enhance_path_recursive "Env Var BEFORE - depth=%depth%" + %print_debug% :enhance_path_recursive "Found Subdirectory - '%%~fi'" + call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position% + %print_debug% :enhance_path_recursive "Env Var AFTER- depth=%depth%" + ) + exit /b diff --git a/vendor/lib/lib_profile.cmd b/vendor/lib/lib_profile.cmd index c0449b9..2a72e9d 100644 --- a/vendor/lib/lib_profile.cmd +++ b/vendor/lib/lib_profile.cmd @@ -1,45 +1,45 @@ -@echo off - -call "%~dp0lib_base.cmd" -call "%~dp0lib_console.cmd" -set lib_profile=call "%~dp0lib_profile.cmd" - -if "%~1" == "/h" ( - %lib_base% help "%~0" -) else if "%~1" neq "" ( - call :%* -) - -exit /b - -:::=============================================================================== -:::run_profile_d - Run all scripts in the passed directory path -:::. -:::include: -:::. -::: call "lib_profile.cmd" -:::. -:::usage: -:::. -::: %lib_profile% "[dir_path]" -:::. -:::required: -:::. -::: [dir_path] Fully qualified directory path containing init *.cmd|*.bat. -::: Example: "c:\bin" -:::. -::: path Sets the path env variable if required. -:::------------------------------------------------------------------------------- - -:run_profile_d - if not exist "%~1" ( - mkdir "%~1" - ) - - pushd "%~1" - for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do ( - %print_verbose% "Calling '%~1\%%x'..." - call "%~1\%%x" - ) - popd - exit /b +@echo off + +call "%~dp0lib_base.cmd" +call "%~dp0lib_console.cmd" +set lib_profile=call "%~dp0lib_profile.cmd" + +if "%~1" == "/h" ( + %lib_base% help "%~0" +) else if "%~1" neq "" ( + call :%* +) + +exit /b + +:::=============================================================================== +:::run_profile_d - Run all scripts in the passed directory path +:::. +:::include: +:::. +::: call "lib_profile.cmd" +:::. +:::usage: +:::. +::: %lib_profile% "[dir_path]" +:::. +:::required: +:::. +::: [dir_path] Fully qualified directory path containing init *.cmd|*.bat. +::: Example: "c:\bin" +:::. +::: path Sets the path env variable if required. +:::------------------------------------------------------------------------------- + +:run_profile_d + if not exist "%~1" ( + mkdir "%~1" + ) + + pushd "%~1" + for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do ( + %print_verbose% "Calling '%~1\%%x'..." + call "%~1\%%x" + ) + popd + exit /b