mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 17:59:11 +08:00
a5bdecca77
The below enables Cmder Fast Init mode for `cmd.exe` sessions. This is more like the Cmder 1.3.5 init process. See issue #1821 Cmder Fast Init mode bypasses or disables the following Cmder 1.3.6+ features: * Git root and version detection. Defaults to `%cmder_root%\vendor\git-for-windows` if it exists. * Path enhance validation before path modify so `%Path%` enhancements are forced. * Recursive path add for `"%CMDER_ROOT%\bin"` * Recursive path add for `"%CMDER_USER_BIN%\bin"` if `/c [user_config_folder` is specified. * `/d` switch to enable debug output. * `/v` switch to enable debug output. Add `/f` to Cmder task as shown below t enable fast init: _Note 1: This setting is invalid in Cmder `Powershell` and `Bash` sessions~_ _Note 2: Add `/t` also to see init timer output_ ![image](https://user-images.githubusercontent.com/7318053/47957637-052e3880-df90-11e8-93ef-91e1ab696d82.png) Cuts ~2.4 seconds off of init time. ![image](https://user-images.githubusercontent.com/7318053/47957795-45db8100-df93-11e8-8ae0-551d12c4e2dc.png)
175 lines
4.8 KiB
Batchfile
175 lines
4.8 KiB
Batchfile
@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 "lib_path.cmd"
|
|
:::
|
|
:::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="
|
|
)
|
|
|
|
if "%fast_init%" == "1" (
|
|
if "%position%" == "append" (
|
|
set "PATH=%PATH%;%add_path%"
|
|
) else (
|
|
set "PATH=%add_path%;%PATH%"
|
|
)
|
|
goto :end_enhance_path
|
|
)
|
|
|
|
set found=0
|
|
set "find_query=%add_path%"
|
|
set "find_query=%find_query:\=\\%"
|
|
set "find_query=%find_query: =\ %"
|
|
|
|
if "%CMDER_CONFIGURED%" == "1" (
|
|
%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" (
|
|
if "%CMDER_CONFIGURED%" == "1" (
|
|
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!"
|
|
)
|
|
|
|
:end_enhance_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 "%fast_init%" == "1" (
|
|
call :enhance_path "%add_path%" %position%
|
|
goto :end_enhance_path_recursive
|
|
)
|
|
|
|
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!"
|
|
)
|
|
)
|
|
|
|
:end_enhance_path_recursive
|
|
endlocal & set "PATH=%PATH%"
|
|
exit /b
|