mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-30 17:01:57 +08:00 
			
		
		
		
	## Rename user-profile.* user_profile.* to resolve #1806, #1675 * This is a backward compatible fix and will automatically and silently rename users '%cmder_root%/config/user-profile.\*' to '%cmder_root%/config/user_profile.\*' and '[user_specified_config_root]/user-profile.\*' to '[user_specified_config_root]/user_profile.\*' if the sources exist. * Cmder.exe does this for cmd.exe sessions. * The init scripts for bash and Powershell handles it for these shells
This commit is contained in:
		
				
					committed by
					
						 Benjamin Staneck
						Benjamin Staneck
					
				
			
			
				
	
			
			
			
						parent
						
							e4fb0d694b
						
					
				
				
					commit
					49da3745bc
				
			
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -14,8 +14,10 @@ build/ | ||||
| Version v* | ||||
| *.bak | ||||
| config/user-* | ||||
| config/user_* | ||||
| config/settings | ||||
| config/aliases | ||||
| config/profile.d | ||||
| .github_changelog_generator | ||||
| launcher/.vs | ||||
| launcher/src/version.rc2 | ||||
|   | ||||
							
								
								
									
										22
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								README.md
									
									
									
									
									
								
							| @@ -117,7 +117,7 @@ From a bash/mintty shell: | ||||
| cd $CMDER_ROOT/vendor | ||||
| git clone https://github.com/karlin/mintty-colors-solarized.git | ||||
| cd mintty-colors-solarized/ | ||||
| echo source \$CMDER_ROOT/vendor/mintty-colors-solarized/mintty-solarized-dark.sh>>$CMDER_ROOT/config/user-profile.sh | ||||
| echo source \$CMDER_ROOT/vendor/mintty-colors-solarized/mintty-solarized-dark.sh>>$CMDER_ROOT/config/user_profile.sh | ||||
| ``` | ||||
|  | ||||
| You may find some Monokai color schemes for mintty to match Cmder [here](https://github.com/PhilipDaniels/mintty/blob/master/themes/Monokai) or [here](https://github.com/oumu/mintty-color-schemes/blob/master/base16-monokai-mod.minttyrc). | ||||
| @@ -154,11 +154,11 @@ Single user portable configuration is possible using the cmder specific shell co | ||||
|  | ||||
| | Shell         | Cmder Portable User Config                | | ||||
| | ------------- | ----------------------------------------- | | ||||
| | Cmder         | `%CMDER_ROOT%\\config\\user-profile.cmd`    | | ||||
| | PowerShell    | `$ENV:CMDER_ROOT\\config\\user-profile.ps1` | | ||||
| | Bash/Mintty   | `$CMDER_ROOT/config/user-profile.sh`        | | ||||
| | Cmder         | `%CMDER_ROOT%\\config\\user_profile.cmd`    | | ||||
| | PowerShell    | `$ENV:CMDER_ROOT\\config\\user_profile.ps1` | | ||||
| | Bash/Mintty   | `$CMDER_ROOT/config/user_profile.sh`        | | ||||
|  | ||||
| Note: Bash and Mintty sessions will also source the `$HOME/.bashrc` file if it exists after it sources `$CMDER_ROOT/config/user-profile.sh`. | ||||
| Note: Bash and Mintty sessions will also source the `$HOME/.bashrc` file if it exists after it sources `$CMDER_ROOT/config/user_profile.sh`. | ||||
|  | ||||
| You can write `*.cmd|*.bat`, `*.ps1`, and `*.sh` scripts and just drop them in the `%CMDER_ROOT%\config\profile.d` folder to add startup config to Cmder. | ||||
|  | ||||
| @@ -182,7 +182,7 @@ Note: These are loaded in this order by `$CMDER_ROOT/vendor/init.bat`.  Anything | ||||
|  | ||||
| * `%CMDER_ROOT%\\config\\profile.d\\\*.cmd` and `\*.bat` | ||||
| * `%CMDER_ROOT%\\config\\user-aliases.cmd` | ||||
| * `%CMDER_ROOT%\\config\\user-profile.cmd` | ||||
| * `%CMDER_ROOT%\\config\\user_profile.cmd` | ||||
|  | ||||
| #### Bash.exe|Mintty.exe Aliases | ||||
| Bash shells support simple and complex aliases with optional parameters natively so they work a little different.  Typing `alias name=command` will create an alias only for the current running session. | ||||
| @@ -192,26 +192,26 @@ To make an alias and/or any other profile settings permanent add it to one of th | ||||
| Note: These are loaded in this order by `$CMDER_ROOT/vendor/git-for-windows/etc/profile.d/cmder.sh`.  Anything stored in `$CMDER_ROOT` will be a portable setting and will follow cmder to another machine. | ||||
|  | ||||
| * `$CMDER_ROOT/config/profile.d/*.sh` | ||||
| * `$CMDER_ROOT/config/user-profile.sh` | ||||
| * `$CMDER_ROOT/config/user_profile.sh` | ||||
| * `$HOME/.bashrc` | ||||
|  | ||||
| If you add bash aliases to `$CMDER_ROOT/config/user-profile.sh` they will be portable and follow your Cmder folder if you copy it to another machine.  `$HOME/.bashrc` defined aliases are not portable. | ||||
| If you add bash aliases to `$CMDER_ROOT/config/user_profile.sh` they will be portable and follow your Cmder folder if you copy it to another machine.  `$HOME/.bashrc` defined aliases are not portable. | ||||
|  | ||||
| #### PowerShell.exe Aliases | ||||
| PowerShell has native simple alias support, for example `[new-alias | set-alias] alias command`, so complex aliases with optional parameters are not supported in PowerShell sessions.  Type `get-help [new-alias|set-alias] -full` for help on PowerShell aliases. | ||||
|  | ||||
| To make an alias and/or any other profile settings permanent add it to one of the following: | ||||
|  | ||||
| Note: These are loaded in this order by `$ENV:CMDER_ROOT\\vendor\\user-profile.ps1`.  Anything stored in `$ENV:CMDER_ROOT` will be a portable setting and will follow cmder to another machine. | ||||
| Note: These are loaded in this order by `$ENV:CMDER_ROOT\\vendor\\user_profile.ps1`.  Anything stored in `$ENV:CMDER_ROOT` will be a portable setting and will follow cmder to another machine. | ||||
|  | ||||
| * '$ENV:CMDER_ROOT\\config\\profile.d\\\*.ps1' | ||||
| * '$ENV:CMDER_ROOT\\config\\user-profile.ps1' | ||||
| * '$ENV:CMDER_ROOT\\config\\user_profile.ps1' | ||||
|  | ||||
| ### SSH Agent | ||||
|  | ||||
| To start the vendored SSH agent simply call `start-ssh-agent`, which is in the `vendor/git-for-windows/cmd` folder. | ||||
|  | ||||
| If you want to run SSH agent on startup, include the line `@call "%GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd"` in `%CMDER_ROOT%/config/user-profile.cmd` (usually just uncomment it). | ||||
| If you want to run SSH agent on startup, include the line `@call "%GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd"` in `%CMDER_ROOT%/config/user_profile.cmd` (usually just uncomment it). | ||||
|  | ||||
| ### Vendored Git | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
| #include <iostream> | ||||
|  | ||||
| #pragma comment(lib, "Shlwapi.lib") | ||||
| #pragma warning( disable : 4091 ) | ||||
|  | ||||
| #ifndef UNICODE | ||||
| #error "Must be compiled with unicode support." | ||||
| @@ -85,6 +86,8 @@ void StartCmder(std::wstring  path = L"", bool is_single_mode = false, std::wstr | ||||
| 	wchar_t userConfigDirPath[MAX_PATH] = { 0 }; | ||||
| 	wchar_t userBinDirPath[MAX_PATH] = { 0 }; | ||||
| 	wchar_t userProfiledDirPath[MAX_PATH] = { 0 }; | ||||
| 	wchar_t userProfilePath[MAX_PATH] = { 0 }; | ||||
| 	wchar_t legacyUserProfilePath[MAX_PATH] = { 0 }; | ||||
| 	wchar_t args[MAX_PATH * 2 + 256] = { 0 }; | ||||
|  | ||||
| 	std::wstring cmderStart = path; | ||||
| @@ -104,6 +107,21 @@ void StartCmder(std::wstring  path = L"", bool is_single_mode = false, std::wstr | ||||
| 	PathCombine(icoPath, exeDir, L"icons\\cmder.ico"); | ||||
|  | ||||
| 	PathCombine(configDirPath, exeDir, L"config"); | ||||
|  | ||||
| 	PathCombine(legacyUserProfilePath, configDirPath, L"user-profile.cmd"); | ||||
| 	if (PathFileExists(legacyUserProfilePath)) { | ||||
| 		PathCombine(userProfilePath, configDirPath, L"user_profile.cmd"); | ||||
|  | ||||
| 		char      *lPr = (char *)malloc(MAX_PATH); | ||||
| 		char      *pR = (char *)malloc(MAX_PATH); | ||||
| 		size_t i; | ||||
| 		wcstombs_s(&i, lPr, (size_t)MAX_PATH, | ||||
| 			legacyUserProfilePath, (size_t)MAX_PATH); | ||||
| 		wcstombs_s(&i, pR, (size_t)MAX_PATH, | ||||
| 			userProfilePath, (size_t)MAX_PATH); | ||||
| 		rename(lPr, pR); | ||||
| 	} | ||||
|  | ||||
| 	if (wcscmp(userConfigDirPath, L"") == 0) | ||||
| 	{ | ||||
| 		PathCombine(userConfigDirPath, exeDir, L"config"); | ||||
| @@ -118,6 +136,20 @@ void StartCmder(std::wstring  path = L"", bool is_single_mode = false, std::wstr | ||||
|  | ||||
| 		PathCombine(userProfiledDirPath, userConfigDirPath, L"profile.d"); | ||||
| 		SHCreateDirectoryEx(0, userProfiledDirPath, 0); | ||||
| 		 | ||||
| 		PathCombine(legacyUserProfilePath, userConfigDirPath, L"user-profile.cmd"); | ||||
| 		if (PathFileExists(legacyUserProfilePath)) { | ||||
| 			PathCombine(userProfilePath, userConfigDirPath, L"user_profile.cmd"); | ||||
|  | ||||
| 			char      *lPr = (char *)malloc(MAX_PATH); | ||||
| 			char      *pR = (char *)malloc(MAX_PATH); | ||||
| 			size_t i; | ||||
| 			wcstombs_s(&i, lPr, (size_t)MAX_PATH, | ||||
| 				legacyUserProfilePath, (size_t)MAX_PATH); | ||||
| 			wcstombs_s(&i, pR, (size_t)MAX_PATH, | ||||
| 				userProfilePath, (size_t)MAX_PATH); | ||||
| 			rename(lPr, pR); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	// Set path to vendored ConEmu config file | ||||
| @@ -131,7 +163,6 @@ void StartCmder(std::wstring  path = L"", bool is_single_mode = false, std::wstr | ||||
| 	ExpandEnvironmentStrings(cpuCfgPath, cpuCfgPath, sizeof(cpuCfgPath) / sizeof(cpuCfgPath[0])); | ||||
|  | ||||
| 	PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml"); | ||||
|  | ||||
| 	if (PathFileExists(cpuCfgPath)) { | ||||
| 		if (PathFileExists(cfgPath)) { | ||||
| 			if (!CopyFile(cfgPath, cpuCfgPath, FALSE)) | ||||
|   | ||||
							
								
								
									
										31
									
								
								vendor/cmder.sh
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										31
									
								
								vendor/cmder.sh
									
									
									
									
										vendored
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| # DO NOT EDIT THIS FILE IT WILL BE OVERWRITTEN ON UPDATE | ||||
| # | ||||
| # Add portable user customizations ${CMDER_ROOT}/config/user-profile.sh, | ||||
| # Add portable user customizations ${CMDER_ROOT}/config/user_profile.sh, | ||||
| # these customizations will follow Cmder if $CMDER_ROOT is copied | ||||
| # to another machine. | ||||
| # | ||||
| @@ -63,21 +63,32 @@ if [ -d "${CMDER_USER_CONFIG}/profile.d" ] ; then | ||||
|   runProfiled  "${CMDER_USER_CONFIG}/profile.d" | ||||
| fi | ||||
|  | ||||
| initialConfig="${CMDER_ROOT}/config/user-profile.sh" | ||||
| if [ -f "${CMDER_ROOT}/config/user-profile.sh" ] ; then | ||||
|     . "${CMDER_ROOT}/config/user-profile.sh" | ||||
|  | ||||
| # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency. | ||||
| if [ -f "$CMDER_ROOT/config/user-profile.sh" ] ; then | ||||
|   mv "$CMDER_ROOT/config/user-profile.sh" "$CMDER_ROOT/config/user_profile.sh" | ||||
| fi | ||||
|  | ||||
| CmderUserProfilePath="${CMDER_ROOT}/config/user_profile.sh" | ||||
| if [ -f "${CMDER_ROOT}/config/user_profile.sh" ] ; then | ||||
|     . "${CMDER_ROOT}/config/user_profile.sh" | ||||
| fi | ||||
|  | ||||
| if [ "${CMDER_USER_CONFIG}" != "" ] ; then | ||||
|   initialConfig="${CMDER_USER_CONFIG}/user-profile.sh" | ||||
|   if [ -f "${CMDER_USER_CONFIG}/user-profile.sh" ] ; then | ||||
|     . "${CMDER_USER_CONFIG}/user-profile.sh" | ||||
|   # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency. | ||||
|   if [ -f "$CMDER_USER_CONFIG/user-profile.sh" ] ; then | ||||
|     mv "$CMDER_USER_CONFIG/user-profile.sh" "$CMDER_USER_CONFIG/user_profile.sh" | ||||
|   fi | ||||
|  | ||||
|   CmderUserProfilePath="${CMDER_USER_CONFIG}/user_profile.sh" | ||||
|   if [ -f "${CMDER_USER_CONFIG}/user_profile.sh" ] ; then | ||||
|     . "${CMDER_USER_CONFIG}/user_profile.sh" | ||||
|   fi | ||||
| fi | ||||
|  | ||||
| if [ ! -f "${initialConfig}" ] ; then | ||||
|     echo Creating user startup file: "${initialConfig}" | ||||
|     cat <<-eof >"${initialConfig}" | ||||
| if [ ! -f "${CmderUserProfilePath}" ] ; then | ||||
|     echo Creating user startup file: "${CmderUserProfilePath}" | ||||
|     cat <<-eof >"${CmderUserProfilePath}" | ||||
| # use this file to run your own startup commands for msys2 bash' | ||||
|  | ||||
| # To add a new vendor to the path, do something like: | ||||
|   | ||||
							
								
								
									
										34
									
								
								vendor/cmder_exinit
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										34
									
								
								vendor/cmder_exinit
									
									
									
									
										vendored
									
									
								
							| @@ -82,21 +82,31 @@ if [ ! "$CMDER_ROOT" = "" ] ; then | ||||
|   fi | ||||
|  | ||||
|  | ||||
|   if [ -f "${CMDER_ROOT}/config/user-profile.sh" ] ; then | ||||
|     . "${CMDER_ROOT}/config/user-profile.sh" | ||||
|   # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency. | ||||
|   if [ -f "$CMDER_ROOT/config/user-profile.sh" ] ; then | ||||
|     mv "$CMDER_ROOT/config/user-profile.sh" "$CMDER_ROOT/config/user_profile.sh" | ||||
|   fi | ||||
|  | ||||
|   if [ -f "${CMDER_USER_CONFIG}/user-profile.sh" ] ; then | ||||
|       . "${CMDER_USER_CONFIG}/user-profile.sh" | ||||
|   else | ||||
|       if [ "${CMDER_USER_CONFIG}" != "" ] ; then | ||||
|         initialProfile="${CMDER_USER_CONFIG}/user-profile.sh" | ||||
|       else | ||||
|         initialProfile="${CMDER_ROOT}/config/user-profile.sh" | ||||
|       fi | ||||
|   CmderUserProfilePath="${CMDER_ROOT}/config/user_profile.sh" | ||||
|   if [ -f "${CMDER_ROOT}/config/user_profile.sh" ] ; then | ||||
|       . "${CMDER_ROOT}/config/user_profile.sh" | ||||
|   fi | ||||
|  | ||||
|       echo Creating user startup file: "${initialProfile}" | ||||
|     cat <<-eof >"${initialProfile}" | ||||
|   if [ "${CMDER_USER_CONFIG}" != "" ] ; then | ||||
|     # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency. | ||||
|     if [ -f "$CMDER_USER_CONFIG/user-profile.sh" ] ; then | ||||
|       mv "$CMDER_USER_CONFIG/user-profile.sh" "$CMDER_USER_CONFIG/user_profile.sh" | ||||
|     fi | ||||
|  | ||||
|     CmderUserProfilePath="${CMDER_USER_CONFIG}/user_profile.sh" | ||||
|     if [ -f "${CMDER_USER_CONFIG}/user_profile.sh" ] ; then | ||||
|       . "${CMDER_USER_CONFIG}/user_profile.sh" | ||||
|     fi | ||||
|   fi | ||||
|  | ||||
|   if [ ! -f "${CmderUserProfilePath}" ] ; then | ||||
|       echo Creating user startup file: "${CmderUserProfilePath}" | ||||
|       cat <<-eof >"${CmderUserProfilePath}" | ||||
| # use this file to run your own startup commands for msys2 bash' | ||||
|  | ||||
| # To add a new vendor to the path, do something like: | ||||
|   | ||||
							
								
								
									
										14
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										14
									
								
								vendor/init.bat
									
									
									
									
										vendored
									
									
								
							| @@ -4,7 +4,7 @@ | ||||
| :: Created as part of cmder project | ||||
|  | ||||
| :: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED | ||||
| :: !!! 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. | ||||
| set verbose-output=0 | ||||
| @@ -294,17 +294,17 @@ if exist "%GIT_INSTALL_ROOT%\post-install.bat" ( | ||||
| if not defined HOME set "HOME=%USERPROFILE%" | ||||
| %lib_console% debug-output init.bat "Env Var - HOME=%HOME%" | ||||
|  | ||||
| set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd" | ||||
| if exist "%CMDER_ROOT%\config\user-profile.cmd" ( | ||||
| set "initialConfig=%CMDER_ROOT%\config\user_profile.cmd" | ||||
| if exist "%CMDER_ROOT%\config\user_profile.cmd" ( | ||||
|     REM Create this file and place your own command in there | ||||
|     call "%CMDER_ROOT%\config\user-profile.cmd" | ||||
|     call "%CMDER_ROOT%\config\user_profile.cmd" | ||||
| ) | ||||
|  | ||||
| if defined CMDER_USER_CONFIG ( | ||||
|   set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd" | ||||
|   if exist "%CMDER_USER_CONFIG%\user-profile.cmd" ( | ||||
|   set "initialConfig=%CMDER_USER_CONFIG%\user_profile.cmd" | ||||
|   if exist "%CMDER_USER_CONFIG%\user_profile.cmd" ( | ||||
|       REM Create this file and place your own command in there | ||||
|       call "%CMDER_USER_CONFIG%\user-profile.cmd" | ||||
|       call "%CMDER_USER_CONFIG%\user_profile.cmd" | ||||
|   ) | ||||
| ) | ||||
|  | ||||
|   | ||||
							
								
								
									
										18
									
								
								vendor/profile.ps1
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										18
									
								
								vendor/profile.ps1
									
									
									
									
										vendored
									
									
								
							| @@ -2,7 +2,7 @@ | ||||
| # Created as part of cmder project | ||||
|  | ||||
| # !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED | ||||
| # !!! Use "%CMDER_ROOT%\config\user-profile.ps1" to add your own startup commands | ||||
| # !!! Use "%CMDER_ROOT%\config\user_profile.ps1" to add your own startup commands | ||||
|  | ||||
| # Compatibility with PS major versions <= 2 | ||||
| if(!$PSScriptRoot) { | ||||
| @@ -97,7 +97,7 @@ $env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT" | ||||
|  | ||||
| # | ||||
| # Prompt Section | ||||
| #   Users should modify their user-profile.ps1 as it will be safe from updates. | ||||
| #   Users should modify their user_profile.ps1 as it will be safe from updates. | ||||
| # | ||||
|  | ||||
| # Pre assign the hooks so the first run of cmder gets a working prompt. | ||||
| @@ -149,16 +149,24 @@ if ($ENV:CMDER_USER_CONFIG -ne "" -and (test-path "$ENV:CMDER_USER_CONFIG\profil | ||||
|     popd | ||||
| } | ||||
|      | ||||
| # Renaming to "config\user_profile.ps1" to "user_profile.ps1" for consistency. | ||||
| if (test-path "$env:CMDER_ROOT\config\user-profile.ps1") { | ||||
|   rename-item  "$env:CMDER_ROOT\config\user-profile.ps1" user_profile.ps1 | ||||
| } | ||||
|  | ||||
|  | ||||
| $CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user-profile.ps1" | ||||
| $CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user_profile.ps1" | ||||
| if (Test-Path $CmderUserProfilePath) { | ||||
|     # Create this file and place your own command in there. | ||||
|     Import-Module "$CmderUserProfilePath" | ||||
| } | ||||
|  | ||||
| if ($ENV:CMDER_USER_CONFIG) { | ||||
|     $CmderUserProfilePath = Join-Path $ENV:CMDER_USER_CONFIG "user-profile.ps1" | ||||
|     # Renaming to "$env:CMDER_USER_CONFIG\user-profile.ps1" to "user_profile.ps1" for consistency. | ||||
|     if (test-path "$env:CMDER_USER_CONFIG\user-profile.ps1") { | ||||
|       rename-item  "$env:CMDER_USER_CONFIG\user-profile.ps1" user_profile.ps1 | ||||
|     } | ||||
|  | ||||
|     $CmderUserProfilePath = Join-Path $ENV:CMDER_USER_CONFIG "user_profile.ps1" | ||||
|     if (Test-Path $CmderUserProfilePath) { | ||||
|       Import-Module "$CmderUserProfilePath" | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user