## 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:
Dax T Games 2018-08-31 17:02:56 -05:00 committed by Benjamin Staneck
parent e4fb0d694b
commit 49da3745bc
7 changed files with 120 additions and 58 deletions

2
.gitignore vendored
View File

@ -14,8 +14,10 @@ build/
Version v* Version v*
*.bak *.bak
config/user-* config/user-*
config/user_*
config/settings config/settings
config/aliases config/aliases
config/profile.d config/profile.d
.github_changelog_generator .github_changelog_generator
launcher/.vs launcher/.vs
launcher/src/version.rc2

View File

@ -117,7 +117,7 @@ From a bash/mintty shell:
cd $CMDER_ROOT/vendor cd $CMDER_ROOT/vendor
git clone https://github.com/karlin/mintty-colors-solarized.git git clone https://github.com/karlin/mintty-colors-solarized.git
cd mintty-colors-solarized/ 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). 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 | | Shell | Cmder Portable User Config |
| ------------- | ----------------------------------------- | | ------------- | ----------------------------------------- |
| Cmder | `%CMDER_ROOT%\\config\\user-profile.cmd` | | Cmder | `%CMDER_ROOT%\\config\\user_profile.cmd` |
| PowerShell | `$ENV:CMDER_ROOT\\config\\user-profile.ps1` | | PowerShell | `$ENV:CMDER_ROOT\\config\\user_profile.ps1` |
| Bash/Mintty | `$CMDER_ROOT/config/user-profile.sh` | | 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. 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\\profile.d\\\*.cmd` and `\*.bat`
* `%CMDER_ROOT%\\config\\user-aliases.cmd` * `%CMDER_ROOT%\\config\\user-aliases.cmd`
* `%CMDER_ROOT%\\config\\user-profile.cmd` * `%CMDER_ROOT%\\config\\user_profile.cmd`
#### Bash.exe|Mintty.exe Aliases #### 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. 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. 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/profile.d/*.sh`
* `$CMDER_ROOT/config/user-profile.sh` * `$CMDER_ROOT/config/user_profile.sh`
* `$HOME/.bashrc` * `$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.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. 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: 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\\profile.d\\\*.ps1'
* '$ENV:CMDER_ROOT\\config\\user-profile.ps1' * '$ENV:CMDER_ROOT\\config\\user_profile.ps1'
### SSH Agent ### SSH Agent
To start the vendored SSH agent simply call `start-ssh-agent`, which is in the `vendor/git-for-windows/cmd` folder. 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 ### Vendored Git

View File

@ -9,6 +9,7 @@
#include <iostream> #include <iostream>
#pragma comment(lib, "Shlwapi.lib") #pragma comment(lib, "Shlwapi.lib")
#pragma warning( disable : 4091 )
#ifndef UNICODE #ifndef UNICODE
#error "Must be compiled with unicode support." #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 userConfigDirPath[MAX_PATH] = { 0 };
wchar_t userBinDirPath[MAX_PATH] = { 0 }; wchar_t userBinDirPath[MAX_PATH] = { 0 };
wchar_t userProfiledDirPath[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 }; wchar_t args[MAX_PATH * 2 + 256] = { 0 };
std::wstring cmderStart = path; 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(icoPath, exeDir, L"icons\\cmder.ico");
PathCombine(configDirPath, exeDir, L"config"); 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) if (wcscmp(userConfigDirPath, L"") == 0)
{ {
PathCombine(userConfigDirPath, exeDir, L"config"); 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"); PathCombine(userProfiledDirPath, userConfigDirPath, L"profile.d");
SHCreateDirectoryEx(0, userProfiledDirPath, 0); 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 // 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])); ExpandEnvironmentStrings(cpuCfgPath, cpuCfgPath, sizeof(cpuCfgPath) / sizeof(cpuCfgPath[0]));
PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml"); PathCombine(userCfgPath, userConfigDirPath, L"user-ConEmu.xml");
if (PathFileExists(cpuCfgPath)) { if (PathFileExists(cpuCfgPath)) {
if (PathFileExists(cfgPath)) { if (PathFileExists(cfgPath)) {
if (!CopyFile(cfgPath, cpuCfgPath, FALSE)) if (!CopyFile(cfgPath, cpuCfgPath, FALSE))

31
vendor/cmder.sh vendored
View File

@ -1,6 +1,6 @@
# DO NOT EDIT THIS FILE IT WILL BE OVERWRITTEN ON UPDATE # 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 # these customizations will follow Cmder if $CMDER_ROOT is copied
# to another machine. # to another machine.
# #
@ -63,21 +63,32 @@ if [ -d "${CMDER_USER_CONFIG}/profile.d" ] ; then
runProfiled "${CMDER_USER_CONFIG}/profile.d" runProfiled "${CMDER_USER_CONFIG}/profile.d"
fi fi
initialConfig="${CMDER_ROOT}/config/user-profile.sh"
if [ -f "${CMDER_ROOT}/config/user-profile.sh" ] ; then # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency.
. "${CMDER_ROOT}/config/user-profile.sh" 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 fi
if [ "${CMDER_USER_CONFIG}" != "" ] ; then if [ "${CMDER_USER_CONFIG}" != "" ] ; then
initialConfig="${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 if [ -f "$CMDER_USER_CONFIG/user-profile.sh" ] ; then
. "${CMDER_USER_CONFIG}/user-profile.sh" 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
fi fi
if [ ! -f "${initialConfig}" ] ; then if [ ! -f "${CmderUserProfilePath}" ] ; then
echo Creating user startup file: "${initialConfig}" echo Creating user startup file: "${CmderUserProfilePath}"
cat <<-eof >"${initialConfig}" cat <<-eof >"${CmderUserProfilePath}"
# use this file to run your own startup commands for msys2 bash' # use this file to run your own startup commands for msys2 bash'
# To add a new vendor to the path, do something like: # To add a new vendor to the path, do something like:

30
vendor/cmder_exinit vendored
View File

@ -82,21 +82,31 @@ if [ ! "$CMDER_ROOT" = "" ] ; then
fi fi
if [ -f "${CMDER_ROOT}/config/user-profile.sh" ] ; then # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency.
. "${CMDER_ROOT}/config/user-profile.sh" 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 fi
if [ -f "${CMDER_USER_CONFIG}/user-profile.sh" ] ; then
. "${CMDER_USER_CONFIG}/user-profile.sh"
else
if [ "${CMDER_USER_CONFIG}" != "" ] ; then if [ "${CMDER_USER_CONFIG}" != "" ] ; then
initialProfile="${CMDER_USER_CONFIG}/user-profile.sh" # Renaming to "config\user_profile.sh" to "user_profile.sh" for consistency.
else if [ -f "$CMDER_USER_CONFIG/user-profile.sh" ] ; then
initialProfile="${CMDER_ROOT}/config/user-profile.sh" mv "$CMDER_USER_CONFIG/user-profile.sh" "$CMDER_USER_CONFIG/user_profile.sh"
fi fi
echo Creating user startup file: "${initialProfile}" CmderUserProfilePath="${CMDER_USER_CONFIG}/user_profile.sh"
cat <<-eof >"${initialProfile}" 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' # use this file to run your own startup commands for msys2 bash'
# To add a new vendor to the path, do something like: # To add a new vendor to the path, do something like:

14
vendor/init.bat vendored
View File

@ -4,7 +4,7 @@
:: Created as part of cmder project :: Created as part of cmder project
:: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED :: !!! 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. :: Use /v command line arg or set to > 0 for verbose output to aid in debugging.
set verbose-output=0 set verbose-output=0
@ -294,17 +294,17 @@ if exist "%GIT_INSTALL_ROOT%\post-install.bat" (
if not defined HOME set "HOME=%USERPROFILE%" if not defined HOME set "HOME=%USERPROFILE%"
%lib_console% debug-output init.bat "Env Var - HOME=%HOME%" %lib_console% debug-output init.bat "Env Var - HOME=%HOME%"
set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd" set "initialConfig=%CMDER_ROOT%\config\user_profile.cmd"
if exist "%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 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 ( if defined CMDER_USER_CONFIG (
set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd" set "initialConfig=%CMDER_USER_CONFIG%\user_profile.cmd"
if exist "%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 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
View File

@ -2,7 +2,7 @@
# Created as part of cmder project # Created as part of cmder project
# !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED # !!! 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 # Compatibility with PS major versions <= 2
if(!$PSScriptRoot) { if(!$PSScriptRoot) {
@ -97,7 +97,7 @@ $env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT"
# #
# Prompt Section # 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. # 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 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) { if (Test-Path $CmderUserProfilePath) {
# Create this file and place your own command in there. # Create this file and place your own command in there.
Import-Module "$CmderUserProfilePath" Import-Module "$CmderUserProfilePath"
} }
if ($ENV:CMDER_USER_CONFIG) { 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) { if (Test-Path $CmderUserProfilePath) {
Import-Module "$CmderUserProfilePath" Import-Module "$CmderUserProfilePath"
} }