mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 09:22:15 +08:00 
			
		
		
		
	Made all sub-routines in init.bat importable libs (#1706)
This commit is contained in:
		
							
								
								
									
										286
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										286
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							| @@ -27,6 +27,12 @@ if not defined CMDER_ROOT ( | ||||
| :: Remove trailing '\' from %CMDER_ROOT% | ||||
| if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%" | ||||
|  | ||||
| call "%cmder_root%\vendor\lib\lib_base" | ||||
| call "%cmder_root%\vendor\lib\lib_path" | ||||
| call "%cmder_root%\vendor\lib\lib_console" | ||||
| call "%cmder_root%\vendor\lib\lib_git" | ||||
| call "%cmder_root%\vendor\lib\lib_profile" | ||||
|  | ||||
| :var_loop | ||||
|     if "%~1" == "" ( | ||||
|         goto :start | ||||
| @@ -39,7 +45,7 @@ if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%" | ||||
|             set "max_depth=%~2" | ||||
|             shift | ||||
|         ) else ( | ||||
|             call :show_error '/max_depth' requires a number between 1 and 5! | ||||
|             %lib_console% show_error "'/max_depth' requires a number between 1 and 5!" | ||||
|             exit /b | ||||
|         ) | ||||
|     ) else if "%1" == "/c" ( | ||||
| @@ -60,7 +66,7 @@ if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%" | ||||
|             set "GIT_INSTALL_ROOT=%~2" | ||||
|             shift | ||||
|         ) else ( | ||||
|             call :show_error The Git install root folder "%2", you specified does not exist! | ||||
|             %lib_console% show_error "The Git install root folder "%~2", you specified does not exist!" | ||||
|             exit /b | ||||
|         ) | ||||
|     ) else if "%1" == "/home" ( | ||||
| @@ -68,7 +74,7 @@ if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%" | ||||
|             set "HOME=%~2" | ||||
|             shift | ||||
|         ) else ( | ||||
|             call :show_error The home folder "%2", you specified does not exist! | ||||
|             %lib_console% show_error The home folder "%2", you specified does not exist! | ||||
|             exit /b | ||||
|         ) | ||||
|     ) else if "%1" == "/svn_ssh" ( | ||||
| @@ -79,12 +85,11 @@ if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%" | ||||
| goto var_loop | ||||
|  | ||||
| :start | ||||
|  | ||||
| call :debug-output init.bat - Env Var - CMDER_ROOT=%CMDER_ROOT% | ||||
| call :debug-output init.bat - Env Var - debug-output=%debug-output% | ||||
| %lib_console% debug-output init.bat "Env Var - CMDER_ROOT=%CMDER_ROOT%" | ||||
| %lib_console% debug-output init.bat "Env Var - debug-output=%debug-output%" | ||||
|  | ||||
| if defined CMDER_USER_CONFIG ( | ||||
|     call :debug-output init.bat - CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'! | ||||
|     %lib_console% debug-output init.bat "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'!" | ||||
| ) | ||||
|  | ||||
| :: Pick right version of clink | ||||
| @@ -125,12 +130,13 @@ if not defined TERM set TERM=cygwin | ||||
| :: * last, use our vendored git | ||||
| :: also check that we have a recent enough version of git by examining the version string | ||||
| if defined GIT_INSTALL_ROOT ( | ||||
|     if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (goto :FOUND_GIT) | ||||
|     if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" goto :FOUND_GIT) | ||||
| ) | ||||
|  | ||||
| :: get the version information for vendored git binary | ||||
| setlocal enabledelayedexpansion | ||||
| call :read_version VENDORED "%CMDER_ROOT%\vendor\git-for-windows\cmd" | ||||
| %lib_git% read_version VENDORED "%CMDER_ROOT%\vendor\git-for-windows\cmd" | ||||
| %lib_git% validate_version VENDORED !GIT_VERSION_VENDORED! | ||||
|  | ||||
| :: check if git is in path... | ||||
| for /F "delims=" %%F in ('where git.exe 2^>nul') do ( | ||||
| @@ -140,11 +146,12 @@ for /F "delims=" %%F in ('where git.exe 2^>nul') do ( | ||||
|     popd | ||||
|  | ||||
|     :: get the version information for the user provided git binary | ||||
|     call :read_version USER "!test_dir!" | ||||
|     %lib_git% read_version USER "!test_dir!" | ||||
|     %lib_git% validate_version USER !GIT_VERSION_USER! | ||||
|  | ||||
|     if !errorlevel! geq 0 ( | ||||
|         :: compare the user git version against the vendored version | ||||
|         call :compare_versions USER VENDORED | ||||
|         %lib_git% compare_versions USER VENDORED | ||||
|  | ||||
|         :: use the user provided git if its version is greater than, or equal to the vendored git | ||||
|         if !errorlevel! geq 0 if exist "!test_dir:~0,-4!\cmd\git.exe" ( | ||||
| @@ -175,7 +182,7 @@ for /F "delims=" %%F in ('where git.exe 2^>nul') do ( | ||||
| :VENDORED_GIT | ||||
| if exist "%CMDER_ROOT%\vendor\git-for-windows" ( | ||||
|     set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows" | ||||
|     call :enhance_path "!GIT_INSTALL_ROOT!\cmd"  | ||||
|     %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd"  | ||||
| ) else ( | ||||
|     goto :NO_GIT | ||||
| ) | ||||
| @@ -184,33 +191,34 @@ if exist "%CMDER_ROOT%\vendor\git-for-windows" ( | ||||
| :: Add git to the path | ||||
| if defined GIT_INSTALL_ROOT ( | ||||
|     rem add the unix commands at the end to not shadow windows commands like more | ||||
|     if exist "!GIT_INSTALL_ROOT!\cmd\git.exe" call :enhance_path "!GIT_INSTALL_ROOT!\cmd" append | ||||
|     if exist "!GIT_INSTALL_ROOT!\cmd\git.exe" %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd" append | ||||
|     if exist "!GIT_INSTALL_ROOT!\mingw32" ( | ||||
|         call :enhance_path "!GIT_INSTALL_ROOT!\mingw32" append | ||||
|         %lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw32" append | ||||
|     ) else if exist "!GIT_INSTALL_ROOT!\mingw64" ( | ||||
|         call :enhance_path "!GIT_INSTALL_ROOT!\mingw64" append | ||||
|         %lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw64" append | ||||
|     ) | ||||
|     if exist "!GIT_INSTALL_ROOT!\usr\bin" call :enhance_path "%GIT_INSTALL_ROOT%\usr\bin" append | ||||
|     %lib_path% enhance_path "%GIT_INSTALL_ROOT%\usr\bin" append | ||||
|  | ||||
|     :: define SVN_SSH so we can use git svn with ssh svn repositories | ||||
|     if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe" | ||||
| ) | ||||
|  | ||||
| :NO_GIT | ||||
| endlocal & set "PATH=%PATH%" & set "SVN_SSH=%SVN_SSH%" & set "GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%" | ||||
| call :debug-output init.bat - Env Var - GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT% | ||||
| %lib_console% debug-output init.bat "Env Var - GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%" | ||||
|  | ||||
| :: Enhance Path | ||||
| call :enhance_path_recursive "%CMDER_ROOT%\bin" %max_depth% | ||||
| %lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" %max_depth%  | ||||
| if defined CMDER_USER_BIN ( | ||||
|   call :enhance_path "%CMDER_USER_BIN%" %max_depth% | ||||
|   %lib_path% enhance_path_recursive "%CMDER_USER_BIN%" %max_depth% | ||||
| ) | ||||
| call :enhance_path "%CMDER_ROOT%" append | ||||
| %lib_path% enhance_path "%CMDER_ROOT%" append | ||||
|  | ||||
| :: Drop *.bat and *.cmd files into "%CMDER_ROOT%\config\profile.d" | ||||
| :: to run them at startup. | ||||
| call :run_profile_d "%CMDER_ROOT%\config\profile.d" | ||||
| %lib_profile% run_profile_d "%CMDER_ROOT%\config\profile.d" | ||||
| if defined CMDER_USER_CONFIG ( | ||||
|   call :run_profile_d "%CMDER_USER_CONFIG%\profile.d" | ||||
|   %lib_profile% run_profile_d "%CMDER_USER_CONFIG%\profile.d" | ||||
| ) | ||||
|  | ||||
| :: Allows user to override default aliases store using profile.d | ||||
| @@ -269,7 +277,7 @@ call "%user-aliases%" | ||||
| :: Basically we need to execute this post-install.bat because we are | ||||
| :: manually extracting the archive rather than executing the 7z sfx | ||||
| if exist "%GIT_INSTALL_ROOT%\post-install.bat" ( | ||||
|     call :verbose-output Running Git for Windows one time Post Install.... | ||||
|     %lib_console% verbose-output "Running Git for Windows one time Post Install...." | ||||
|     pushd "%GIT_INSTALL_ROOT%\" | ||||
|     "%GIT_INSTALL_ROOT%\git-bash.exe" --no-needs-console --hide --no-cd --command=post-install.bat | ||||
|     popd | ||||
| @@ -277,7 +285,7 @@ if exist "%GIT_INSTALL_ROOT%\post-install.bat" ( | ||||
|  | ||||
| :: Set home path | ||||
| if not defined HOME set "HOME=%USERPROFILE%" | ||||
| call :debug-output init.bat - Env Var - HOME=%HOME% | ||||
| %lib_console% debug-output init.bat "Env Var - HOME=%HOME%" | ||||
|  | ||||
| if exist "%CMDER_ROOT%\config\user-profile.cmd" ( | ||||
|     REM Create this file and place your own command in there | ||||
| @@ -314,233 +322,3 @@ echo @echo off | ||||
| ) | ||||
|  | ||||
| exit /b | ||||
|  | ||||
| :: | ||||
| :: sub-routines below here | ||||
| :: | ||||
| :debug-output | ||||
|     if %debug-output% gtr 0 echo %* & echo. | ||||
|     exit /b | ||||
|  | ||||
| :verbose-output | ||||
|     if %debug-output% gtr 0 ( | ||||
|       call :debug-output :verbose-output - %* | ||||
|     ) else if %verbose-output% gtr 0 ( | ||||
|       echo %* | ||||
|     ) | ||||
|     exit /b | ||||
|  | ||||
| :show_error | ||||
|     echo ERROR: %* | ||||
|     echo CMDER Shell Initialization has Failed! | ||||
|     exit /b | ||||
|  | ||||
| :run_profile_d | ||||
|   if not exist "%~1" ( | ||||
|     mkdir "%~1" | ||||
|   ) | ||||
|    | ||||
|   pushd "%~1" | ||||
|   for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do ( | ||||
|     call :verbose-output Calling "%~1\%%x"... | ||||
|     call "%~1\%%x" | ||||
|   ) | ||||
|   popd | ||||
|   exit /b | ||||
|  | ||||
| :: | ||||
| :: specific to git version comparing | ||||
| :: | ||||
| :read_version | ||||
|     :: clear the variables | ||||
|     set GIT_VERSION_%~1= | ||||
|  | ||||
|     :: set the executable path | ||||
|     set "git_executable=%~2\git.exe" | ||||
|     call :debug-output :read_version - Env Var - git_executable=%git_executable% | ||||
|  | ||||
|     :: check if the executable actually exists | ||||
|     if not exist "%git_executable%" ( | ||||
|         call :verbose-output "%git_executable%" does not exist! | ||||
|         exit /b -255 | ||||
|     ) | ||||
|  | ||||
|     :: get the git version in the provided directory | ||||
|     for /F "tokens=1,2,3 usebackq" %%F in (`"%git_executable%" --version 2^>nul`) do ( | ||||
|         if "%%F %%G" == "git version" ( | ||||
|             set "GIT_VERSION_%~1=%%H" | ||||
|             call :debug-output :read_version - Env Var - GIT_VERSION_%~1=%%H | ||||
|         ) else ( | ||||
|             echo "git --version" returned an inproper version string! | ||||
|             pause | ||||
|             exit /b | ||||
|         ) | ||||
|     ) | ||||
|  | ||||
|     :: parse the returned string | ||||
|     call :debug-output :read_version - Calling - :validate_version "%~1" !GIT_VERSION_%~1! | ||||
|     call :validate_version "%~1" !GIT_VERSION_%~1! | ||||
|     exit /b | ||||
|  | ||||
| :parse_version | ||||
|     :: process a `x.x.x.xxxx.x` formatted string | ||||
|     for /F "tokens=1-3* delims=.,-" %%A in ("%2") do ( | ||||
|         set "%~1_MAJOR=%%A" | ||||
|         set "%~1_MINOR=%%B" | ||||
|         set "%~1_PATCH=%%C" | ||||
|         set "%~1_BUILD=%%D" | ||||
|     ) | ||||
|     exit /b | ||||
|  | ||||
| :validate_version | ||||
|     :: now parse the version information into the corresponding variables | ||||
|     call :parse_version %~1 %~2 | ||||
|  | ||||
|     :: ... and maybe display it, for debugging purposes. | ||||
|     call :debug-output :validate_version - Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD! | ||||
|     exit /b | ||||
|  | ||||
| :compare_versions | ||||
|     :: checks all major, minor, patch and build variables for the given arguments. | ||||
|     :: whichever binary that has the most recent version will be used based on the return code. | ||||
|  | ||||
|     :: call :debug-output Comparing: | ||||
|     :: call :debug-output %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD! | ||||
|     :: call :debug-output %~2: !%~2_MAJOR!.!%~2_MINOR!.!%~2_PATCH!.!%~2_BUILD! | ||||
|  | ||||
|     if !%~1_MAJOR! GTR !%~2_MAJOR! (exit /b  1) | ||||
|     if !%~1_MAJOR! LSS !%~2_MAJOR! (exit /b -1) | ||||
|  | ||||
|     if !%~1_MINOR! GTR !%~2_MINOR! (exit /b  1) | ||||
|     if !%~1_MINOR! LSS !%~2_MINOR! (exit /b -1) | ||||
|  | ||||
|     if !%~1_PATCH! GTR !%~2_PATCH! (exit /b  1) | ||||
|     if !%~1_PATCH! LSS !%~2_PATCH! (exit /b -1) | ||||
|  | ||||
|     if !%~1_BUILD! GTR !%~2_BUILD! (exit /b  1) | ||||
|     if !%~1_BUILD! LSS !%~2_BUILD! (exit /b -1) | ||||
|  | ||||
|     :: looks like we have the same versions. | ||||
|     exit /b 0 | ||||
|  | ||||
| :enhance_path | ||||
|     setlocal enabledelayedexpansion | ||||
|     if "%~1" neq "" ( | ||||
|         if exist "%~1" ( | ||||
|             set "add_path=%~1" | ||||
|         ) else ( | ||||
|             call :show_error :enhance_path - The path specified. "%~1", does not exist! | ||||
|             exit 1 | ||||
|         ) | ||||
|     ) else ( | ||||
|         call :show_error You must specify a directory to add to the path! | ||||
|         exit 1 | ||||
|     ) | ||||
|      | ||||
|     if "%~2" neq "" if /i "%~2" == "append" ( | ||||
|         set "position=%~2" | ||||
|     ) else ( | ||||
|         set "position=" | ||||
|     ) | ||||
|  | ||||
|     set "find_query=%add_path%" | ||||
|     set "find_query=%find_query:\=\\%" | ||||
|     set "find_query=%find_query: =\ %" | ||||
|     set found=0 | ||||
|  | ||||
|     call :debug-output  :enhance_path "Env Var - find_query=%find_query%" | ||||
|     echo "%PATH%"|findstr >nul /I /R ";%find_query%\"$" | ||||
|     if "!ERRORLEVEL!" == "0" set found=1 | ||||
|  | ||||
|     call :debug-output  :enhance_path "Env Var 1 - found=!found!" | ||||
|     if "!found!" == "0" ( | ||||
|         echo "%PATH%"|findstr >nul /i /r ";%find_query%;" | ||||
|         if "!ERRORLEVEL!" == "0" set found=1 | ||||
|         call :debug-output  :enhance_path "Env Var 2 - found=!found!" | ||||
|     ) | ||||
|  | ||||
|     if "%found%" == "0" ( | ||||
|         call :debug-output :enhance_path "BEFORE Env Var - PATH=!path!" | ||||
|         if /i "%position%" == "append" ( | ||||
|             call :debug-output :enhance_path "Appending '%add_path%'" | ||||
|             set "PATH=%PATH%;%add_path%" | ||||
|         ) else ( | ||||
|             call :debug-output :enhance_path "Prepending '%add_path%'" | ||||
|             set "PATH=%add_path%;%PATH%" | ||||
|         ) | ||||
|  | ||||
|         call :debug-output  :enhance_path "AFTER Env Var - PATH=!path!" | ||||
|     ) | ||||
|  | ||||
|     endlocal & set "PATH=%PATH%" | ||||
|     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] <in> Fully qualified directory path. Ex: "c:\bin" | ||||
| :::  | ||||
| :::dptions:  | ||||
| :::  | ||||
| :::  [max_depth] <in> Max recuse depth.  Default: 1 | ||||
| ::: | ||||
| :::  append      <in> Append instead rather than pre-pend "[dir_path]" | ||||
| :::  | ||||
| :::output: | ||||
| :::  | ||||
| :::  path       <out> Sets the path env variable if required.  | ||||
| ::: ------------------------------------------------------------------------------ | ||||
|  | ||||
|     setlocal enabledelayedexpansion | ||||
|     if "%~1" neq "" ( | ||||
|         set "add_path=%~1" | ||||
|     ) else ( | ||||
|         call :directory to add to the path!" | ||||
|         exit 1 | ||||
|     ) | ||||
|      | ||||
|     if "%~2" gtr "1" ( | ||||
|         set "max_depth=%~2" | ||||
|     ) else ( | ||||
|         set "max_depth=1" | ||||
|     ) | ||||
|  | ||||
|     if "%~3" neq "" if /i "%~3" == "append" ( | ||||
|         set "position=%~3" | ||||
|     ) else ( | ||||
|         set "position=" | ||||
|     ) | ||||
|  | ||||
|     if "%depth%" == "" set depth=0 | ||||
|  | ||||
|     call :debug-output  :enhance_path_recursive "Env Var - add_path=%add_path%" | ||||
|     call :debug-output  :enhance_path_recursive "Env Var - position=%position%" | ||||
|     call :debug-output  :enhance_path_recursive "Env Var - max_depth=%max_depth%" | ||||
|  | ||||
|     if %max_depth% gtr !depth! ( | ||||
|         call :debug-output :enhance_path_recursive "Adding parent directory - '%add_path%'" | ||||
|         call :enhance_path "%add_path%" %position% | ||||
|         set /a "depth=!depth!+1" | ||||
|  | ||||
|         for /d %%i in ("%add_path%\*") do ( | ||||
|             call :debug-output  :enhance_path_recursive "Env Var BEFORE - depth=!depth!" | ||||
|             call :debug-output :enhance_path_recursive "Found Subdirectory - '%%~fi'" | ||||
|             call :enhance_path_recursive "%%~fi" %max_depth% %position% | ||||
|             call :debug-output  :enhance_path_recursive "Env Var AFTER- depth=!depth!" | ||||
|         ) | ||||
|     ) | ||||
|  | ||||
|     endlocal & set "PATH=%PATH%" | ||||
|     exit /b | ||||
|   | ||||
							
								
								
									
										48
									
								
								vendor/lib/lib_base.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								vendor/lib/lib_base.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| @echo off | ||||
|  | ||||
| set lib_base=call "%~dp0lib_base.cmd" | ||||
|  | ||||
| if "%~1" == "/h" ( | ||||
|     %lib_base% help "%0" | ||||
| ) else if "%1" neq "" ( | ||||
|     call :%* | ||||
| ) | ||||
|  | ||||
| exit /b | ||||
|  | ||||
| :help | ||||
| :::=============================================================================== | ||||
| :::show_subs - shows all sub routines in a .bat/.cmd file with documentation | ||||
| :::. | ||||
| :::include: | ||||
| :::. | ||||
| :::       call "$0" | ||||
| :::. | ||||
| :::usage: | ||||
| :::. | ||||
| :::       %lib_base% show_subs "file" | ||||
| :::. | ||||
| :::options: | ||||
| :::. | ||||
| :::       file <in> full path to file containing lib_routines to display | ||||
| :::. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     for /f "tokens=* delims=:" %%a in ('type "%~1" ^| findstr /i /r "^:::"') do ( | ||||
|         rem echo a="%%a" | ||||
|  | ||||
|         if "%%a"==" " ( | ||||
|             echo. | ||||
|         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 | ||||
							
								
								
									
										80
									
								
								vendor/lib/lib_console.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								vendor/lib/lib_console.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| @echo off | ||||
|  | ||||
| rem set args=%* | ||||
|  | ||||
| call "%~dp0lib_base.cmd" | ||||
| set lib_console=call "%~dp0lib_console.cmd" | ||||
|  | ||||
| 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 "$0" | ||||
| :::. | ||||
| :::usage: | ||||
| :::. | ||||
| :::  %lib_console% debug-output [caller] [message] | ||||
| :::. | ||||
| :::required: | ||||
| :::. | ||||
| :::  [caller]  <in> Script/sub routine name calling debug-output | ||||
| :::. | ||||
| :::  [message] <in> Message text to display. | ||||
| :::. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     if %debug-output% gtr 0 echo 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] <in> 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] <in> Message text to display. | ||||
| :::. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     echo ERROR: %~1 | ||||
|     echo CMDER Shell Initialization has Failed! | ||||
|     exit /b | ||||
							
								
								
									
										168
									
								
								vendor/lib/lib_git.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										168
									
								
								vendor/lib/lib_git.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,168 @@ | ||||
| @echo off | ||||
|  | ||||
|  | ||||
| call "%~dp0lib_base.cmd" | ||||
| call "%%~dp0lib_console.cmd" | ||||
| set lib_git=call "%~dp0lib_git.cmd" | ||||
|  | ||||
|  | ||||
| if "%~1" == "/h" ( | ||||
|     %lib_base% help "%0" | ||||
| ) else if "%1" neq "" ( | ||||
|     call :%* | ||||
| ) | ||||
|  | ||||
| exit /b | ||||
|  | ||||
| :read_version | ||||
| :::=============================================================================== | ||||
| :::read_version - Get the git.exe verion | ||||
| :::. | ||||
| :::include: | ||||
| :::. | ||||
| :::  call "$0" | ||||
| :::. | ||||
| :::usage: | ||||
| :::. | ||||
| :::  %lib_git% read_version "[dir_path]" | ||||
| :::. | ||||
| :::required: | ||||
| :::. | ||||
| :::  [GIT SCOPE]   <in> USER | VENDORED | ||||
| :::  [GIT PATH]    <in> Fully qualified path to the Git command root. | ||||
| :::. | ||||
| :::output: | ||||
| :::. | ||||
| :::  GIT_VERSION_[GIT SCOPE] <out> Env variable containing Git semantic version string | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     setlocal enabledelayedexpansion | ||||
|     :: clear the variables | ||||
|     set GIT_VERSION_%~1= | ||||
|  | ||||
|     :: set the executable path | ||||
|     set "git_executable=%~2\git.exe" | ||||
|     %lib_console% debug-output :read_version "Env Var - git_executable=%git_executable%" | ||||
|  | ||||
|     :: check if the executable actually exists | ||||
|     if not exist "%git_executable%" ( | ||||
|         %lib_console% show_error "%git_executable%" does not exist! | ||||
|         exit /b -255 | ||||
|     ) | ||||
|  | ||||
|     :: get the git version in the provided directory | ||||
|     for /F "tokens=1,2,3 usebackq" %%A in (`"%git_executable%" --version 2^>nul`) do ( | ||||
|         if /i "%%A %%B" == "git version" ( | ||||
|             set "GIT_VERSION_%~1=%%C" | ||||
|             %lib_console% debug-output :read_version "Env Var - GIT_VERSION_%~1=%%C" | ||||
|         ) else ( | ||||
|             %lib_console% show_error "git --version" returned an inproper version string! | ||||
|             pause | ||||
|             exit /b | ||||
|         ) | ||||
|     ) | ||||
|  | ||||
|     endlocal & set GIT_VERSION%~1=!GIT_VERSION%~1! | ||||
|     exit /b | ||||
|  | ||||
| :parse_version | ||||
| :::=============================================================================== | ||||
| :::parse_version - Parse semantic version string 'x.x.x.x' and return the pieces | ||||
| :::. | ||||
| :::include: | ||||
| :::. | ||||
| :::  call "$0" | ||||
| :::. | ||||
| :::usage: | ||||
| :::. | ||||
| :::  %lib_git% parse_version "[VERSION]" | ||||
| :::. | ||||
| :::required: | ||||
| :::. | ||||
| :::  [SCOPE]     <in> USER | VENDORED | ||||
| :::  [VERSION]   <in> Semantic version String. Ex: 1.2.3.4 | ||||
| :::. | ||||
| :::output: | ||||
| :::. | ||||
| :::  [SCOPE]_MAJOR <out> Scoped Major version. | ||||
| :::  [SCOPE]_MINOR <out> Scoped Minor version. | ||||
| :::  [SCOPE]_PATCH <out> Scoped Patch version. | ||||
| :::  [SCOPE]_BUILD <out> Scoped Build version. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     setlocal enabledelayedexpansion | ||||
|     :: process a `x.x.x.xxxx.x` formatted string | ||||
|     for /F "tokens=1-3* delims=.,-" %%A in ("%2") do ( | ||||
|         set "%~1_MAJOR=%%A" | ||||
|         set "%~1_MINOR=%%B" | ||||
|         set "%~1_PATCH=%%C" | ||||
|         set "%~1_BUILD=%%D" | ||||
|     ) | ||||
|  | ||||
|     endlocal & set "%~1_MAJOR=!%~1_MAJOR!" & set "%~1_MINOR=!%~1_MINOR!" & set "%~1_PATCH=!%~1_PATCH!" & set "%~1_BUILD=!%~1_BUILD!" | ||||
|     exit /b | ||||
|  | ||||
| :validate_version | ||||
| :::=============================================================================== | ||||
| :::validate_version - Validate semantic version string 'x.x.x.x'. | ||||
| :::. | ||||
| :::include: | ||||
| :::. | ||||
| :::  call "$0" | ||||
| :::. | ||||
| :::usage: | ||||
| :::. | ||||
| :::  %lib_git% validate_version [SCOPE] [VERSION] | ||||
| :::. | ||||
| :::required: | ||||
| :::. | ||||
| :::  [SCOPE]     <in> Example:  USER | VENDORED | ||||
| :::  [VERSION]   <in> Semantic version String. Ex: 1.2.3.4 | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     :: now parse the version information into the corresponding variables | ||||
|     call :parse_version %~1 %~2 | ||||
|  | ||||
|     :: ... and maybe display it, for debugging purposes. | ||||
|     %lib_console% debug-output :validate_version "Found Git Version for %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD!" | ||||
|     exit /b | ||||
|  | ||||
| :compare_versions | ||||
| :::=============================================================================== | ||||
| :::compare_version - Compare semantic versions return latest version. | ||||
| :::. | ||||
| :::include: | ||||
| :::. | ||||
| :::  call "$0" | ||||
| :::. | ||||
| :::usage: | ||||
| :::. | ||||
| :::  %lib_git% validate_version [SCOPE1] [SCOPE2] | ||||
| :::. | ||||
| :::required: | ||||
| :::. | ||||
| :::  [SCOPE1]    <in> Example: USER | ||||
| :::  [SCOPE2]    <in> Example: VENDOR | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     :: checks all major, minor, patch and build variables for the given arguments. | ||||
|     :: whichever binary that has the most recent version will be used based on the return code. | ||||
|  | ||||
|     :: %lib_console% debug-output Comparing: | ||||
|     :: %lib_console% debug-output %~1: !%~1_MAJOR!.!%~1_MINOR!.!%~1_PATCH!.!%~1_BUILD! | ||||
|     :: %lib_console% debug-output %~2: !%~2_MAJOR!.!%~2_MINOR!.!%~2_PATCH!.!%~2_BUILD! | ||||
|  | ||||
|     if !%~1_MAJOR! GTR !%~2_MAJOR! (exit /b  1) | ||||
|     if !%~1_MAJOR! LSS !%~2_MAJOR! (exit /b -1) | ||||
|  | ||||
|     if !%~1_MINOR! GTR !%~2_MINOR! (exit /b  1) | ||||
|     if !%~1_MINOR! LSS !%~2_MINOR! (exit /b -1) | ||||
|  | ||||
|     if !%~1_PATCH! GTR !%~2_PATCH! (exit /b  1) | ||||
|     if !%~1_PATCH! LSS !%~2_PATCH! (exit /b -1) | ||||
|  | ||||
|     if !%~1_BUILD! GTR !%~2_BUILD! (exit /b  1) | ||||
|     if !%~1_BUILD! LSS !%~2_BUILD! (exit /b -1) | ||||
|  | ||||
|     :: looks like we have the same versions. | ||||
|     exit /b 0 | ||||
							
								
								
									
										155
									
								
								vendor/lib/lib_path.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										155
									
								
								vendor/lib/lib_path.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,155 @@ | ||||
| @echo off | ||||
|  | ||||
|  | ||||
| call "%~dp0lib_base.cmd" | ||||
| call "%%~dp0lib_console" | ||||
| set lib_path=call "%~dp0lib_path.cmd" | ||||
|  | ||||
| if "%~1" == "/h" ( | ||||
|     %lib_base% help "%0" | ||||
| ) else if "%1" neq "" ( | ||||
|     call :%* | ||||
| ) | ||||
|  | ||||
| exit /b | ||||
|  | ||||
| :enhance_path | ||||
| :::=============================================================================== | ||||
| :::enhance_path - Add a directory to the path env variable if required. | ||||
| ::: | ||||
| :::include: | ||||
| ::: | ||||
| :::  call "$0" | ||||
| ::: | ||||
| :::usage: | ||||
| ::: | ||||
| :::  %lib_path% enhance_path "[dir_path]" [append] | ||||
| ::: | ||||
| :::required: | ||||
| ::: | ||||
| :::  [dir_path] <in> Fully qualified directory path. Ex: "c:\bin" | ||||
| ::: | ||||
| :::options: | ||||
| ::: | ||||
| :::  append     <in> Append to the path env variable rather than pre-pend. | ||||
| ::: | ||||
| :::output: | ||||
| ::: | ||||
| :::  path       <out> Sets the path env variable if required. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     setlocal enabledelayedexpansion | ||||
|     if "%~1" neq "" ( | ||||
|         set "add_path=%~1" | ||||
|     ) else ( | ||||
|         %lib_console% show_error "You must specify a directory to add to the path!" | ||||
|         exit 1 | ||||
|     ) | ||||
|  | ||||
|     if "%~2" neq "" if /i "%~2" == "append" ( | ||||
|         set "position=%~2" | ||||
|     ) else ( | ||||
|         set "position=" | ||||
|     ) | ||||
|  | ||||
|     set "find_query=%add_path%" | ||||
|     set "find_query=%find_query:\=\\%" | ||||
|     set "find_query=%find_query: =\ %" | ||||
|     set found=0 | ||||
|  | ||||
|     %lib_console% debug-output  :enhance_path "Env Var - find_query=%find_query%" | ||||
|     echo "%PATH%"|findstr >nul /I /R ";%find_query%\"$" | ||||
|     if "!ERRORLEVEL!" == "0" set found=1 | ||||
|  | ||||
|     %lib_console% debug-output  :enhance_path "Env Var 1 - found=!found!" | ||||
|     if "!found!" == "0" ( | ||||
|         echo "%PATH%"|findstr >nul /i /r ";%find_query%;" | ||||
|         if "!ERRORLEVEL!" == "0" set found=1 | ||||
|         %lib_console% debug-output  :enhance_path "Env Var 2 - found=!found!" | ||||
|     ) | ||||
|  | ||||
|     if "%found%" == "0" ( | ||||
|         %lib_console% debug-output :enhance_path "BEFORE Env Var - PATH=!path!" | ||||
|         if /i "%position%" == "append" ( | ||||
|             %lib_console% debug-output :enhance_path "Appending '%add_path%'" | ||||
|             set "PATH=%PATH%;%add_path%" | ||||
|         ) else ( | ||||
|             %lib_console% debug-output :enhance_path "Prepending '%add_path%'" | ||||
|             set "PATH=%add_path%;%PATH%" | ||||
|         ) | ||||
|  | ||||
|         %lib_console% debug-output  :enhance_path "AFTER Env Var - PATH=!path!" | ||||
|     ) | ||||
|  | ||||
|     endlocal & set "PATH=%PATH:;;=;%" | ||||
|     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] <in> Fully qualified directory path. Ex: "c:\bin" | ||||
| :::. | ||||
| :::options: | ||||
| :::. | ||||
| :::  [max_depth] <in> Max recuse depth.  Default: 1 | ||||
| :::. | ||||
| :::  append      <in> Append instead to path env variable rather than pre-pend. | ||||
| :::. | ||||
| :::output: | ||||
| :::. | ||||
| :::  path       <out> Sets the path env variable if required. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|     setlocal enabledelayedexpansion | ||||
|     if "%~1" neq "" ( | ||||
|         set "add_path=%~1" | ||||
|     ) else ( | ||||
|         %lib_console% show_error "You must specify a directory to add to the path!" | ||||
|         exit 1 | ||||
|     ) | ||||
|  | ||||
|     if "%~2" gtr "1" ( | ||||
|         set "max_depth=%~2" | ||||
|     ) else ( | ||||
|         set "max_depth=1" | ||||
|     ) | ||||
|  | ||||
|     if "%~3" neq "" if /i "%~3" == "append" ( | ||||
|         set "position=%~3" | ||||
|     ) else ( | ||||
|         set "position=" | ||||
|     ) | ||||
|  | ||||
|     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 - position=%position%" | ||||
|     %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% | ||||
|         set /a "depth=!depth!+1" | ||||
|  | ||||
|         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% | ||||
|             %lib_console% debug-output  :enhance_path_recursive "Env Var AFTER- depth=!depth!" | ||||
|         ) | ||||
|     ) | ||||
|  | ||||
|     endlocal & set "PATH=%PATH%" | ||||
|     exit /b | ||||
							
								
								
									
										46
									
								
								vendor/lib/lib_profile.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								vendor/lib/lib_profile.cmd
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| @echo off | ||||
|  | ||||
|  | ||||
| call "%~dp0lib_base.cmd" | ||||
| call "%%~dp0lib_console" | ||||
| 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_profile_d - Run all scripts in the passed dir path | ||||
| ::: | ||||
| :::include: | ||||
| ::: | ||||
| :::  call "$0" | ||||
| ::: | ||||
| :::usage: | ||||
| ::: | ||||
| :::  %lib_profile% "[dir_path]" | ||||
| ::: | ||||
| :::required: | ||||
| ::: | ||||
| :::  [dir_path] <in> Fully qualified directory path containing init *.cmd|*.bat. | ||||
| :::                  Example: "c:\bin" | ||||
| ::: | ||||
| :::  path       <out> Sets the path env variable if required. | ||||
| :::------------------------------------------------------------------------------- | ||||
|  | ||||
|   if not exist "%~1" ( | ||||
|     mkdir "%~1" | ||||
|   ) | ||||
|  | ||||
|   pushd "%~1" | ||||
|   for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do ( | ||||
|     %lib_console% verbose-output "Calling '%~1\%%x'..." | ||||
|     call "%~1\%%x" | ||||
|   ) | ||||
|   popd | ||||
|   exit /b | ||||
		Reference in New Issue
	
	Block a user