mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-11-04 11:22:13 +08:00 
			
		
		
		
	Merge pull request #2311 from daxgames/fix_path_enh_recurs
Fix and enhance enhance_path_recursive
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -3,6 +3,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
bin/*
 | 
					bin/*
 | 
				
			||||||
!bin/Readme.md
 | 
					!bin/Readme.md
 | 
				
			||||||
 | 
					opt/*
 | 
				
			||||||
 | 
					!opt/Readme.md
 | 
				
			||||||
 | 
					
 | 
				
			||||||
vendor/*/*
 | 
					vendor/*/*
 | 
				
			||||||
!vendor/bin/*
 | 
					!vendor/bin/*
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								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
 | 
					### Shared Cmder install with Non-Portable Individual User Config
 | 
				
			||||||
1. Download the [latest release](https://github.com/cmderdev/cmder/releases/)
 | 
					1. Download the [latest release](https://github.com/cmderdev/cmder/releases/)
 | 
				
			||||||
2. Extract the archive to a shared location.
 | 
					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.
 | 
					3. (optional) Place your own executable files and custom app folders into the `%cmder_root%\bin`. See: [opt/README.md](./bin/README)
 | 
				
			||||||
4. (optional) Create `%userprofile%\cmder_config\bin` folder to be injected into individual users PATH.  Default is to auto create this on first run.
 | 
					   - This folder to be injected into your PATH by default.
 | 
				
			||||||
5. (optional) Place your own executable files into the `%userprofile%\cmder_config\bin` folder to be injected into your PATH.
 | 
					   - See `/max_depth [1-5]` in 'Command Line Arguments for `init.bat`' table to add subdirectories recursively.
 | 
				
			||||||
6. Run `Cmder.exe` with `/C` command line argument. Example: `cmder.exe /C %userprofile%\cmder_config`
 | 
					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.
 | 
					   * This will create the following directory structure if it is missing.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
     ```
 | 
					     ```
 | 
				
			||||||
     c:\users\[username]\cmder_config
 | 
					     c:\users\[username]\cmder_config
 | 
				
			||||||
     ├───bin
 | 
					     ├───bin
 | 
				
			||||||
     └───config
 | 
					     ├───config
 | 
				
			||||||
         └───profile.d
 | 
					     │   └───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 '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.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
* 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.
 | 
					* 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
 | 
					## Cmder.exe Command Line Arguments
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								opt/Readme.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								opt/Readme.md
									
									
									
									
									
										Normal file
									
								
							@@ -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.
 | 
				
			||||||
							
								
								
									
										4
									
								
								vendor/bin/cexec.cmd
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								vendor/bin/cexec.cmd
									
									
									
									
										vendored
									
									
								
							@@ -19,8 +19,8 @@ set "currenArgu=%~1"
 | 
				
			|||||||
if /i "%currenArgu%" equ "/setPath" (
 | 
					if /i "%currenArgu%" equ "/setPath" (
 | 
				
			||||||
  :: set %flag_exists% shortcut
 | 
					  :: set %flag_exists% shortcut
 | 
				
			||||||
  endlocal
 | 
					  endlocal
 | 
				
			||||||
  set "ccall=call %~dp0cexec.cmd"
 | 
					  set "ccall=call ^"%~dp0cexec.cmd^""
 | 
				
			||||||
  set "cexec=%~dp0cexec.cmd"
 | 
					  set "cexec=^"%~dp0cexec.cmd^""
 | 
				
			||||||
) else if /i "%currenArgu%" == "/?" (
 | 
					) else if /i "%currenArgu%" == "/?" (
 | 
				
			||||||
  goto :help
 | 
					  goto :help
 | 
				
			||||||
) else if /i "%currenArgu%" equ "/help" (
 | 
					) else if /i "%currenArgu%" equ "/help" (
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										40
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										40
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							@@ -9,13 +9,23 @@ set CMDER_INIT_START=%time%
 | 
				
			|||||||
:: !!! Use "%CMDER_ROOT%\config\user_profile.cmd" to add your own startup commands
 | 
					:: !!! 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.
 | 
					:: Use /v command line arg or set to > 0 for verbose output to aid in debugging.
 | 
				
			||||||
set verbose_output=0
 | 
					if not defined verbose_output set verbose_output=0
 | 
				
			||||||
set debug_output=0
 | 
					
 | 
				
			||||||
set time_init=0
 | 
					:: Use /d command line arg or set to 1 for debug output to aid in debugging.
 | 
				
			||||||
set fast_init=0
 | 
					if not defined debug_output set debug_output=0
 | 
				
			||||||
set max_depth=1
 | 
					
 | 
				
			||||||
:: Add *nix tools to end of path. 0 turns off *nix tools.
 | 
					:: Use /t command line arg or set to 1 to display init time.
 | 
				
			||||||
set nix_tools=1
 | 
					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= "
 | 
					set "CMDER_USER_FLAGS= "
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:: Find root dir
 | 
					:: Find root dir
 | 
				
			||||||
@@ -120,6 +130,8 @@ goto var_loop
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if defined CMDER_USER_CONFIG (
 | 
					if defined CMDER_USER_CONFIG (
 | 
				
			||||||
    %lib_console% 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%'!"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if not exist "%CMDER_USER_CONFIG%\opt" md "%CMDER_USER_CONFIG%\opt"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:: Pick right version of clink
 | 
					:: Pick right version of clink
 | 
				
			||||||
@@ -154,6 +166,12 @@ if "%CMDER_CLINK%" == "1" (
 | 
				
			|||||||
  %lib_console% verbose_output "WARNING: Incompatible 'ComSpec/Shell' Detetected Skipping Clink Injection!"
 | 
					  %lib_console% verbose_output "WARNING: Incompatible 'ComSpec/Shell' Detetected Skipping Clink Injection!"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if "%CMDER_CONFIGURED%" == "1" (
 | 
				
			||||||
 | 
					  echo Cmder is already configured, skipping Cmder Init!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  goto CMDER_CONFIGURED
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:: Prepare for git-for-windows
 | 
					:: Prepare for git-for-windows
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:: I do not even know, copypasted from their .bat
 | 
					:: I do not even know, copypasted from their .bat
 | 
				
			||||||
@@ -261,9 +279,11 @@ endlocal
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
:PATH_ENHANCE
 | 
					:PATH_ENHANCE
 | 
				
			||||||
%lib_path% enhance_path "%CMDER_ROOT%\vendor\bin"
 | 
					%lib_path% enhance_path "%CMDER_ROOT%\vendor\bin"
 | 
				
			||||||
%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" %max_depth%
 | 
					
 | 
				
			||||||
 | 
					:USER_CONFIG_START
 | 
				
			||||||
 | 
					%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" 0 %max_depth%
 | 
				
			||||||
if defined CMDER_USER_BIN (
 | 
					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
 | 
					%lib_path% enhance_path "%CMDER_ROOT%" append
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -367,6 +387,8 @@ if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMD
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set initialConfig=
 | 
					set initialConfig=
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					:CMDER_CONFIGURED
 | 
				
			||||||
set CMDER_CONFIGURED=1
 | 
					set CMDER_CONFIGURED=1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set CMDER_INIT_END=%time%
 | 
					set CMDER_INIT_END=%time%
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										63
									
								
								vendor/lib/lib_path.cmd
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										63
									
								
								vendor/lib/lib_path.cmd
									
									
									
									
										vendored
									
									
								
							@@ -51,17 +51,26 @@ exit /b
 | 
				
			|||||||
        set "position="
 | 
					        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 "%fast_init%" == "1" (
 | 
				
			||||||
      if "%position%" == "append" (
 | 
					      if "%position%" == "append" (
 | 
				
			||||||
        set "PATH=%PATH%;%add_path%"
 | 
					        set "PATH=%PATH%;%add_to_path%"
 | 
				
			||||||
      ) else (
 | 
					      ) else (
 | 
				
			||||||
        set "PATH=%add_path%;%PATH%"
 | 
					        set "PATH=%add_to_path%;%PATH%"
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      goto :end_enhance_path
 | 
					      goto :end_enhance_path
 | 
				
			||||||
 | 
					    ) else if "add_to_path" equ "" (
 | 
				
			||||||
 | 
					      goto :end_enhance_path
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set found=0
 | 
					    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 "find_query=%find_query: =\ %"
 | 
					    set "find_query=%find_query: =\ %"
 | 
				
			||||||
    set OLD_PATH=%PATH%
 | 
					    set OLD_PATH=%PATH%
 | 
				
			||||||
@@ -90,11 +99,11 @@ exit /b
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    if "%found%" == "0" (
 | 
					    if "%found%" == "0" (
 | 
				
			||||||
        if /i "%position%" == "append" (
 | 
					        if /i "%position%" == "append" (
 | 
				
			||||||
            %lib_console% debug_output :enhance_path "Appending '%add_path%'"
 | 
					            %lib_console% debug_output :enhance_path "Appending '%add_to_path%'"
 | 
				
			||||||
            set "PATH=%PATH%;%add_path%"
 | 
					            set "PATH=%PATH%;%add_to_path%"
 | 
				
			||||||
        ) else (
 | 
					        ) else (
 | 
				
			||||||
            %lib_console% debug_output :enhance_path "Prepending '%add_path%'"
 | 
					            %lib_console% debug_output :enhance_path "Prepending '%add_to_path%'"
 | 
				
			||||||
            set "PATH=%add_path%;%PATH%"
 | 
					            set "PATH=%add_to_path%;%PATH%"
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        set found=1
 | 
					        set found=1
 | 
				
			||||||
@@ -150,20 +159,26 @@ exit /b
 | 
				
			|||||||
        exit 1
 | 
					        exit 1
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if "%~2" gtr "1" (
 | 
					    set "depth=%~2"
 | 
				
			||||||
        set "max_depth=%~2"
 | 
					    set "max_depth=%~3"
 | 
				
			||||||
    ) else (
 | 
					 | 
				
			||||||
        set "max_depth=1"
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if "%~3" neq "" if /i "%~3" == "append" (
 | 
					    if "%~4" neq "" if /i "%~4" == "append" (
 | 
				
			||||||
        set "position=%~3"
 | 
					        set "position=%~4"
 | 
				
			||||||
    ) else (
 | 
					    ) else (
 | 
				
			||||||
        set "position="
 | 
					        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 "%fast_init%" == "1" (
 | 
				
			||||||
      call :enhance_path "%add_path%" %position%
 | 
					        if "%add_to_path%" neq "" (
 | 
				
			||||||
 | 
					            call :enhance_path "%add_to_path%" %position%
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    set "PATH=%PATH:;;=;%"
 | 
					    set "PATH=%PATH:;;=;%"
 | 
				
			||||||
@@ -171,20 +186,22 @@ exit /b
 | 
				
			|||||||
      exit /b
 | 
					      exit /b
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if "%depth%" == "" set depth=0
 | 
					    %lib_console% debug_output  :enhance_path_recursive "Env Var - add_path=%add_to_path%"
 | 
				
			||||||
 | 
					 | 
				
			||||||
    %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 - 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%"
 | 
					    %lib_console% debug_output  :enhance_path_recursive "Env Var - max_depth=%max_depth%"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if %max_depth% gtr %depth% (
 | 
					    if %max_depth% gtr %depth% (
 | 
				
			||||||
        %lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_path%'"
 | 
					        if "%add_to_path%" neq "" (
 | 
				
			||||||
        call :enhance_path "%add_path%" %position%
 | 
					            %lib_console% debug_output :enhance_path_recursive "Adding parent directory - '%add_to_path%'"
 | 
				
			||||||
 | 
					            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
 | 
				
			||||||
@@ -192,10 +209,14 @@ exit /b
 | 
				
			|||||||
    exit /b
 | 
					    exit /b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
:loop_depth
 | 
					:loop_depth
 | 
				
			||||||
 | 
					    if %depth% == %max_depth% (
 | 
				
			||||||
 | 
					        exit /b
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for /d %%i in ("%add_path%\*") do (
 | 
					    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 "Env Var BEFORE - depth=%depth%"
 | 
				
			||||||
        %lib_console% debug_output :enhance_path_recursive "Found Subdirectory - '%%~fi'"
 | 
					        %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%"
 | 
					        %lib_console% debug_output  :enhance_path_recursive "Env Var AFTER- depth=%depth%"
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    exit /b
 | 
					    exit /b
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user