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