From 1f5ea5e596feb82eb7be0e62e6f8800570629abf Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Wed, 29 Apr 2020 12:03:24 -0400 Subject: [PATCH 1/8] Fix and enhance enhance_path_recursive --- .gitignore | 2 ++ README.md | 22 ++++++++++---- opt/Readme.md | 5 ++++ vendor/init.bat | 6 ++-- vendor/lib/lib_path.cmd | 63 +++++++++++++++++++++++++++-------------- 5 files changed, 69 insertions(+), 29 deletions(-) create mode 100644 opt/Readme.md diff --git a/.gitignore b/.gitignore index bc4fb83..67678bb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ bin/* !bin/Readme.md +opt/* +!opt/Readme.md vendor/*/* !vendor/bin/* diff --git a/README.md b/README.md index 753e5eb..56f3949 100644 --- a/README.md +++ b/README.md @@ -23,19 +23,29 @@ The Cmder's user interface is also designed to be more eye pleasing, and you can ### Shared Cmder install with Non-Portable Individual User Config 1. Download the [latest release](https://github.com/cmderdev/cmder/releases/) 2. Extract the archive to a shared location. -3. (optional) Place your own executable files into the `%cmder_root%\bin` folder to be injected into your PATH. -4. (optional) Create `%userprofile%\cmder_config\bin` folder to be injected into individual users PATH. Default is to auto create this on first run. -5. (optional) Place your own executable files into the `%userprofile%\cmder_config\bin` folder to be injected into your PATH. -6. Run `Cmder.exe` with `/C` command line argument. Example: `cmder.exe /C %userprofile%\cmder_config` +3. (optional) Place your own executable files and custom app folders into the `%cmder_root%\bin`. See: [opt/README.md](./bin/README) + - This folder to be injected into your PATH by default. + - See `/max_depth [1-5]` in blow table to add subdirectories recursively. +4. (optional) Place your own custom app folders into the `%cmder_root%\opt`. See: [opt/README.md](./opt/README) + - This folder will NOT be injected into your PATH so you have total control of what gets added. +5. Run `Cmder.exe` with `/C` command line argument. Example: `cmder.exe /C %userprofile%\cmder_config` * This will create the following directory structure if it is missing. ``` c:\users\[username]\cmder_config ├───bin - └───config - └───profile.d + ├───config + │ └───profile.d + └───opt ``` + - (optional) Place your own executable files and custom app folders into `%userprofile%\cmder_config\bin`. + - This folder to be injected into your PATH by default. + - See `/max_depth [1-5]` in blow table to add subdirectories recursively. + - (optional) Place your own custom app folders into the `%user_profile%\cmder_config\opt`. + - This folder will NOT be injected into your PATH so you have total control of what gets added. + + * Both the shared install and the individual user config locations can contain a full set of init and profile.d scripts enabling shared config with user overrides. See below. ## Cmder.exe Command Line Arguments diff --git a/opt/Readme.md b/opt/Readme.md new file mode 100644 index 0000000..acf5fd7 --- /dev/null +++ b/opt/Readme.md @@ -0,0 +1,5 @@ +## Bin + +This folder is for optional user packages and will not be automatically injected into the PATH. + +Use `%lib_path% enhance_path "%cmder_root%\[path to folder]"` in `%cmder_root%\config\user_profile.cmd` or `%cmder_root%\config\profile.d\*.cmd` to add to the path. diff --git a/vendor/init.bat b/vendor/init.bat index 6c3acdb..8d36dc0 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -120,6 +120,8 @@ goto var_loop if defined CMDER_USER_CONFIG ( %lib_console% debug_output init.bat "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'!" + + if not exist "%CMDER_USER_CONFIG%\opt" md "%CMDER_USER_CONFIG%\opt" ) :: Pick right version of clink @@ -261,9 +263,9 @@ endlocal :PATH_ENHANCE %lib_path% enhance_path "%CMDER_ROOT%\vendor\bin" -%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" %max_depth% +%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" 0 %max_depth% if defined CMDER_USER_BIN ( - %lib_path% enhance_path_recursive "%CMDER_USER_BIN%" %max_depth% + %lib_path% enhance_path_recursive "%CMDER_USER_BIN%" 0 %max_depth% ) %lib_path% enhance_path "%CMDER_ROOT%" append diff --git a/vendor/lib/lib_path.cmd b/vendor/lib/lib_path.cmd index a1a8fbe..a8fe253 100644 --- a/vendor/lib/lib_path.cmd +++ b/vendor/lib/lib_path.cmd @@ -51,17 +51,26 @@ exit /b set "position=" ) + dir "%add_path%" | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >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_path%" + set "PATH=%PATH%;%add_to_path%" ) else ( - set "PATH=%add_path%;%PATH%" + 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_path%" + set "find_query=%add_to_path%" set "find_query=%find_query:\=\\%" set "find_query=%find_query: =\ %" set OLD_PATH=%PATH% @@ -90,11 +99,11 @@ exit /b if "%found%" == "0" ( if /i "%position%" == "append" ( - %lib_console% debug_output :enhance_path "Appending '%add_path%'" - set "PATH=%PATH%;%add_path%" + %lib_console% debug_output :enhance_path "Appending '%add_to_path%'" + set "PATH=%PATH%;%add_to_path%" ) else ( - %lib_console% debug_output :enhance_path "Prepending '%add_path%'" - set "PATH=%add_path%;%PATH%" + %lib_console% debug_output :enhance_path "Prepending '%add_to_path%'" + set "PATH=%add_to_path%;%PATH%" ) set found=1 @@ -150,20 +159,26 @@ exit /b exit 1 ) - if "%~2" gtr "1" ( - set "max_depth=%~2" - ) else ( - set "max_depth=1" - ) + set "depth=%~2" + set "max_depth=%~3" - if "%~3" neq "" if /i "%~3" == "append" ( - set "position=%~3" + if "%~4" neq "" if /i "%~4" == "append" ( + set "position=%~4" ) else ( set "position=" ) + dir "%add_path%" | findstr -i "\.COM \.EXE \.BAT \.CMD \.PS1 \.VBS" >NUL + if "%ERRORLEVEL%" == "0" ( + set "add_to_path=%add_path%" + ) else ( + set "add_to_path=" + ) + if "%fast_init%" == "1" ( - call :enhance_path "%add_path%" %position% + if "%add_to_path%" neq "" ( + call :enhance_path "%add_to_path%" %position% + ) ) set "PATH=%PATH:;;=;%" @@ -171,20 +186,22 @@ exit /b exit /b ) - 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 - add_path=%add_to_path%" %lib_console% debug_output :enhance_path_recursive "Env Var - position=%position%" + %lib_console% debug_output :enhance_path_recursive "Env Var - depth=%depth%" %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% + if "%add_to_path%" neq "" ( + %lib_console% debug_output :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 @@ -192,10 +209,14 @@ exit /b exit /b :loop_depth + if %depth% == %max_depth% ( + exit /b + ) + 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% + call :enhance_path_recursive "%%~fi" %depth% %max_depth% %position% %lib_console% debug_output :enhance_path_recursive "Env Var AFTER- depth=%depth%" ) exit /b From 18619834697cfa24521204f95f6bb53117adf775 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Wed, 29 Apr 2020 13:40:39 -0400 Subject: [PATCH 2/8] readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 56f3949..12a2545 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ The Cmder's user interface is also designed to be more eye pleasing, and you can 2. Extract the archive to a shared location. 3. (optional) Place your own executable files and custom app folders into the `%cmder_root%\bin`. See: [opt/README.md](./bin/README) - This folder to be injected into your PATH by default. - - See `/max_depth [1-5]` in blow table to add subdirectories recursively. + - See `/max_depth [1-5]` in 'Command Line Arguments for `init.bat`' table to add subdirectories recursively. 4. (optional) Place your own custom app folders into the `%cmder_root%\opt`. See: [opt/README.md](./opt/README) - This folder will NOT be injected into your PATH so you have total control of what gets added. 5. Run `Cmder.exe` with `/C` command line argument. Example: `cmder.exe /C %userprofile%\cmder_config` @@ -41,7 +41,7 @@ The Cmder's user interface is also designed to be more eye pleasing, and you can - (optional) Place your own executable files and custom app folders into `%userprofile%\cmder_config\bin`. - This folder to be injected into your PATH by default. - - See `/max_depth [1-5]` in blow table to add subdirectories recursively. + - See `/max_depth [1-5]` in 'Command Line Arguments for `init.bat`' table to add subdirectories recursively. - (optional) Place your own custom app folders into the `%user_profile%\cmder_config\opt`. - This folder will NOT be injected into your PATH so you have total control of what gets added. From b91bb84f3d3f19d5783717f6dcc4435a0239e9fb Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 10 May 2020 10:56:12 -0400 Subject: [PATCH 3/8] fix cexec.cmd --- vendor/bin/cexec.cmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/bin/cexec.cmd b/vendor/bin/cexec.cmd index 02ecba5..ba69f3d 100644 --- a/vendor/bin/cexec.cmd +++ b/vendor/bin/cexec.cmd @@ -19,8 +19,8 @@ set "currenArgu=%~1" if /i "%currenArgu%" equ "/setPath" ( :: set %flag_exists% shortcut endlocal - set "ccall=call %~dp0cexec.cmd" - set "cexec=%~dp0cexec.cmd" + set "ccall=call ^"%~dp0cexec.cmd^"" + set "cexec=^"%~dp0cexec.cmd^"" ) else if /i "%currenArgu%" == "/?" ( goto :help ) else if /i "%currenArgu%" equ "/help" ( From 04c784cb16f7743cce10501e3d14bc32aed2c8cb Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 7 Jun 2020 14:49:02 -0400 Subject: [PATCH 4/8] Allow setting cmder init.bat arg vars globally on windows. --- vendor/init.bat | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 8d36dc0..44242b3 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -9,13 +9,22 @@ set CMDER_INIT_START=%time% :: !!! Use "%CMDER_ROOT%\config\user_profile.cmd" to add your own startup commands :: Use /v command line arg or set to > 0 for verbose output to aid in debugging. -set verbose_output=0 -set debug_output=0 -set time_init=0 -set fast_init=0 -set max_depth=1 -:: Add *nix tools to end of path. 0 turns off *nix tools. -set nix_tools=1 +if not defined verbose_output set verbose_output=0 + +:: Use /d command line arg or set to 1 for debug output to aid in debugging. +if not defined debug_output set debug_output=0 + +:: Use /t command line arg or set to 1 to display init time. +if not defined time_init set time_init=0 + +:: Use /f command line arg to speed up init at the expense of some functionality. +if not defined fast_init set fast_init=0 + +:: Use /max_depth 1-5 to set max recurse depth for calls to `enhance_path_recursive` +if not defined max_depth set max_depth=1 + +:: Add *nix tools to end of path. 0 turns off *nix tools, 2 adds *nix tools to the front of thr path. +if not defined nix_tools set nix_tools=1 set "CMDER_USER_FLAGS= " :: Find root dir From a999d17f7164c86baf9407f89c2d2953add66ab8 Mon Sep 17 00:00:00 2001 From: "Dax T. Games" Date: Sun, 7 Jun 2020 15:32:15 -0400 Subject: [PATCH 5/8] Allow setting cmder init.bat arg vars globally on windows. --- vendor/init.bat | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/vendor/init.bat b/vendor/init.bat index 44242b3..aa999a9 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -25,6 +25,7 @@ if not defined max_depth set max_depth=1 :: Add *nix tools to end of path. 0 turns off *nix tools, 2 adds *nix tools to the front of thr path. if not defined nix_tools set nix_tools=1 + set "CMDER_USER_FLAGS= " :: Find root dir @@ -50,6 +51,12 @@ call "%cmder_root%\vendor\lib\lib_console" call "%cmder_root%\vendor\lib\lib_git" call "%cmder_root%\vendor\lib\lib_profile" +if "%CMDER_CONFIGURED%" == "1" ( + echo Cmder is already configured, skipping to user config! + + goto USER_CONFIG_START +) + :var_loop if "%~1" == "" ( goto :start @@ -272,6 +279,8 @@ endlocal :PATH_ENHANCE %lib_path% enhance_path "%CMDER_ROOT%\vendor\bin" + +:USER_CONFIG_START %lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" 0 %max_depth% if defined CMDER_USER_BIN ( %lib_path% enhance_path_recursive "%CMDER_USER_BIN%" 0 %max_depth% From 4d8655984158880311c88a6592dd0f7893e1e644 Mon Sep 17 00:00:00 2001 From: Dax T Games Date: Mon, 8 Jun 2020 21:03:41 -0400 Subject: [PATCH 6/8] Update init.bat Remove cmder_configured goto --- vendor/init.bat | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index aa999a9..ab74229 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -51,11 +51,11 @@ call "%cmder_root%\vendor\lib\lib_console" call "%cmder_root%\vendor\lib\lib_git" call "%cmder_root%\vendor\lib\lib_profile" -if "%CMDER_CONFIGURED%" == "1" ( - echo Cmder is already configured, skipping to user config! - - goto USER_CONFIG_START -) +:: if "%CMDER_CONFIGURED%" == "1" ( +:: echo Cmder is already configured, skipping to user config! +:: +:: goto USER_CONFIG_START +:: ) :var_loop if "%~1" == "" ( From 31c019b7e40d0e505fcec4d53b8c884b2f2fb06c Mon Sep 17 00:00:00 2001 From: Dax T Games Date: Mon, 8 Jun 2020 21:18:23 -0400 Subject: [PATCH 7/8] Update init.bat Move skip to user config below clink enablement in cmder_configured == 1 --- vendor/init.bat | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vendor/init.bat b/vendor/init.bat index ab74229..4043bf3 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -172,6 +172,12 @@ if "%CMDER_CLINK%" == "1" ( %lib_console% verbose_output "WARNING: Incompatible 'ComSpec/Shell' Detetected Skipping Clink Injection!" ) +if "%CMDER_CONFIGURED%" == "1" ( + echo Cmder is already configured, skipping to user config! + + goto USER_CONFIG_START +) + :: Prepare for git-for-windows :: I do not even know, copypasted from their .bat From 8781779636a44078db21d34cf85f5ecee5b854f8 Mon Sep 17 00:00:00 2001 From: Dax T Games Date: Tue, 9 Jun 2020 19:41:08 -0400 Subject: [PATCH 8/8] Update init.bat If CMDER_CONFIGURED==1 skip to :CMDER_CONFIGURED --- vendor/init.bat | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 4043bf3..a4fecf9 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -51,12 +51,6 @@ call "%cmder_root%\vendor\lib\lib_console" call "%cmder_root%\vendor\lib\lib_git" call "%cmder_root%\vendor\lib\lib_profile" -:: if "%CMDER_CONFIGURED%" == "1" ( -:: echo Cmder is already configured, skipping to user config! -:: -:: goto USER_CONFIG_START -:: ) - :var_loop if "%~1" == "" ( goto :start @@ -173,9 +167,9 @@ if "%CMDER_CLINK%" == "1" ( ) if "%CMDER_CONFIGURED%" == "1" ( - echo Cmder is already configured, skipping to user config! + echo Cmder is already configured, skipping Cmder Init! - goto USER_CONFIG_START + goto CMDER_CONFIGURED ) :: Prepare for git-for-windows @@ -393,6 +387,8 @@ if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMD ) set initialConfig= + +:CMDER_CONFIGURED set CMDER_CONFIGURED=1 set CMDER_INIT_END=%time%