diff --git a/Cmder.bat b/Cmder.bat index 1f31b73f4..18d9ff0c0 100644 --- a/Cmder.bat +++ b/Cmder.bat @@ -1,4 +1,11 @@ @echo off SET CMDER_ROOT=%~dp0 -if "%CMDER_ROOT:~-1%" == "\" SET CMDER_ROOT=%CMDER_ROOT:~0,-1% -start %~dp0/vendor/conemu-maximus5/ConEmu.exe /Icon "%CMDER_ROOT%\icons\cmder.ico" /Title Cmder /LoadCfgFile "%CMDER_ROOT%\config\ConEmu.xml" + +:: Remove trailing '\' +@if "%CMDER_ROOT:~-1%" == "\" SET CMDER_ROOT=%CMDER_ROOT:~0,-1% + +if exist "%~1" ( + start %~dp0/vendor/conemu-maximus5/ConEmu.exe /Icon "%CMDER_ROOT%\icons\cmder.ico" /Title Cmder /LoadCfgFile "%~1" +) else ( + start %~dp0/vendor/conemu-maximus5/ConEmu.exe /Icon "%CMDER_ROOT%\icons\cmder.ico" /Title Cmder /LoadCfgFile "%CMDER_ROOT%\config\ConEmu.xml" +) diff --git a/README.md b/README.md index 84958f6fd..5c1c250da 100644 --- a/README.md +++ b/README.md @@ -53,23 +53,73 @@ In a file explorer window right click in or on a directory to see "Cmder Here" i ## Features +### Access to multiple shells in one window using tabs +You can open multiple tabs each containing one of the following shells: + +|Task|Shell|Description| +|----|-----|-----------| +|Cmder|cmd.exe|Windows 'cmd.exe' shell enhanced with Git, Git aware prompt, Clink(GNU Readline), and Aliases.| +|Cmder as Admin|cmd.exe|Administrative Windows 'cmd.exe' Cmder shell.| +|Powershell|powershell.exe|Windows Powershell enhanced with Git and Git aware prompt .| +|Powershell as Admin|powershell.exe|Administrative Windows 'powerhell.exe' Cmder shell.| +|Bash|bash.exe|Unix/Linux like bash shell running on Windows.| +|Bash as Admin|bash.exe|Administrative Unix/Linux like bash shell running on Windows.| +|Mintty|bash.exe|Unix/Linux like bash shell running on Windows. See below for Mintty configuration differences| +|Mintty as Admin|bash.exe|Administrative Unix/Linux like bash shell running on Windows. See below for Mintty configuration differences| + +Cmder, Powershell, and Bash tabs all run on top of the Windows Console API and work as you might expect in Cmder with access to use ConEmu's color schemes, key bindings and other settings defined in the ConEmu Settings dialog. + +Mintty tabs use a program called 'mintty' as the terminal that is not based on the Windows Console API so some differences in functionality are normal, as a result mintty specific config is done via the '[%USERPROFILE%|$HOME]/.minttyrc' file. + +Mintty differs from the other tabs in that it supports xterm/xterm-256color TERM types, and does not work with ConEmu settings like color schemes and key bindings. For more on Mintty and its config click [here](https://code.google.com/p/mintty/). + +An example of setting Cmder portable terminal colors for mintty: + +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 +``` + +### Cmder Portable Shell User Config +User specific configuration is possible using the cmder specific shell config files. Edit the below files to add your own configuration: + +|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| + +Note: Bash and Mintty sessions will also source the '$HOME/.bashrc' file it it exists after it sources '$CMDER_ROOT/config/user-profile.sh'. + ### Aliases -You can define simple aliases with command `alias name=command`. +#### Cmder(Cmd.exe) Aliases +You can define simple aliases for `cmd.exe` sessions with a command like `alias name=command`. Cmd.exe aliases support optional parameters through the `$1-9` or the `$*` special characters so the alias `vi=vim.exe $*` typed as `vi [filename]` will open `[filename]` in `vim.exe`. + +Cmd.exe aliases can also be more complex. See: [DOSKEY.EXE documentation](http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/doskey.mspx?mfr=true) for additional details on complex aliases/macros for 'cmd.exe' + +Aliases defined using the `alias.bat` command will automatically be saved in the `%CMDER_ROOT%\config\aliases` file + +#### 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. To make an alias permanent add it to either your `$CMDER_ROOT/config/user-profile.sh` or your `$HOME/.bashrc`. -For example there is one defined for you `alias e.=explorer .` +If you add bash aliases to `$CMDER_ROOT/config/user-profile.sh` they will portable and follow your Cmder folder if you copy it to another machine. `$HOME/.bashrc` defined aliases are not portable. -All aliases will be saved in `/config/aliases` file +#### 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. ### SSH Agent To start 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 `/config/user-startup.bat` (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). ## Todo -1. Git Bash -2. Check for clink and git before injecting them (Sort of done) +1. Check for clink and git before injecting them (Sort of done) ## License diff --git a/config/ConEmu.xml b/config/ConEmu.xml index f675df06a..bd520e22d 100644 --- a/config/ConEmu.xml +++ b/config/ConEmu.xml @@ -1,7 +1,7 @@ - + @@ -72,7 +72,7 @@ - + @@ -123,12 +123,12 @@ - + - - + + @@ -483,51 +483,89 @@ - - - - - - + + + + + + - - - - + + + + - - + + - + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + @@ -628,7 +666,7 @@ - + @@ -805,7 +843,20 @@ + + + + + + + + + + + + + diff --git a/config/Readme.md b/config/Readme.md index f8dbce285..1ed4f5113 100644 --- a/config/Readme.md +++ b/config/Readme.md @@ -1,3 +1,14 @@ ## Config -All config files must be in this folder. If there is no option to create or read from this folder directly, it must be hardlinked. +All config files must be in this folder. If there is no option to set this folder +directly, it has to be hardlinked. + +* `aliases`: aliases in cmd; called form vendor\init.bat; autocreated from + `vendor\aliases.example`. +* `*.lua`: clink completitions and prompt filters; called from vendor\cmder.lua after all + other prompt filter and clink completitons are initialized; add your own. +* `user_profile.{sh|bat|ps1}: startup files for bash|cmd|powershell tasks; called from their + respective startup scripts in `vendor\`; autocreated on first start of such a task +* `.history`: the current commandline history; autoupdated on close +* `settings`: settings for readline; overwritten on update +* `ConEmu.xml`: settings from ConEmu (=the UI of cmder -> Preferences); overwritten on update diff --git a/config/settings b/config/settings deleted file mode 100644 index ea1bd7e41..000000000 --- a/config/settings +++ /dev/null @@ -1,43 +0,0 @@ -# name: Ctrl-D exits -# type: bool -# Ctrl-D exits the process when it is pressed on an empty line. -ctrld_exits = 1 - -# name: Ctrl-C raises exception -# type: bool -# When Ctrl-C is pressed Clink will pass it thourgh to the parent by raising the -# appropriate exception. -passthrough_ctrlc = 1 - -# name: Esc clears line -# type: bool -# Clink clears the current line when Esc is pressed (unless Readline's Vi mode -# is enabled). -esc_clears_line = 1 - -# name: Match display colour -# type: int -# Colour to use when displaying matches. A value less than 0 will be the -# opposite brightness of the default colour. -match_colour = -1 - -# name: Executable match style -# type: enum -# Changes how Clink will match executables when there is no path separator on -# the line. 0 = PATH only, 1 = PATH and CWD, 2 = PATH, CWD, and directories. In -# all cases both executables and directories are matched when there is a path -# separator present. -exec_match_style = 2 - -# name: Prompt colour -# type: int -# Surrounds the prompt in ANSI escape codes to set the prompt's colour. Disabled -# when the value is less than 0. -prompt_colour = -1 - -# name: Auto-answer terminate prompt -# type: enum -# Automatically answers cmd.exe's 'Terminate batch job (Y/N)?' prompts. 0 = -# disabled, 1 = answer 'Y', 2 = answer 'N'. -terminate_autoanswer = 0 - diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index 49f836aae..510d8ade2 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -3,6 +3,8 @@ #include #include "resource.h" #include +#include + #pragma comment(lib, "Shlwapi.lib") @@ -18,7 +20,7 @@ #define SHELL_MENU_REGISTRY_PATH_BACKGROUND L"Directory\\Background\\shell\\Cmder" #define SHELL_MENU_REGISTRY_PATH_LISTITEM L"Directory\\shell\\Cmder" -#define streqi(a, b) (_wcsicmp((a), (b)) == 0) +#define streqi(a, b) (_wcsicmp((a), (b)) == 0) #define WIDEN2(x) L ## x #define WIDEN(x) WIDEN2(x) @@ -29,7 +31,7 @@ void ShowErrorAndExit(DWORD ec, const wchar_t * func, int line) { wchar_t * buffer; - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, ec, 0, (LPWSTR) &buffer, 0, NULL) == 0) { buffer = L"Unknown error. FormatMessage failed."; @@ -63,10 +65,12 @@ optpair GetOption() if (argc == 1) { + // no commandline argument... pair = optpair(L"/START", L""); } else if (argc == 2 && argv[1][0] != L'/') { + // only a single argument: this should be a path... pair = optpair(L"/START", argv[1]); } else @@ -113,8 +117,21 @@ void StartCmder(std::wstring path, bool is_single_mode) PathRemoveFileSpec(exeDir); PathCombine(icoPath, exeDir, L"icons\\cmder.ico"); - PathCombine(oldCfgPath, exeDir, L"config\\ConEmu.xml"); - PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.xml"); + + // Check for machine-specific config file. + PathCombine(oldCfgPath, exeDir, L"config\\ConEmu-%COMPUTERNAME%.xml"); + ExpandEnvironmentStrings(oldCfgPath, oldCfgPath, sizeof(oldCfgPath) / sizeof(oldCfgPath[0])); + if (!PathFileExists(oldCfgPath)) { + PathCombine(oldCfgPath, exeDir, L"config\\ConEmu.xml"); + } + + // Check for machine-specific config file. + PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu-%COMPUTERNAME%.xml"); + ExpandEnvironmentStrings(cfgPath, cfgPath, sizeof(cfgPath) / sizeof(cfgPath[0])); + if (!PathFileExists(cfgPath)) { + PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.xml"); + } + PathCombine(conEmuPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.exe"); if (FileExists(oldCfgPath) && !FileExists(cfgPath)) @@ -129,17 +146,35 @@ void StartCmder(std::wstring path, bool is_single_mode) } } - if (is_single_mode) + if (is_single_mode) { swprintf_s(args, L"/single /Icon \"%s\" /Title Cmder", icoPath); } - else + else { swprintf_s(args, L"/Icon \"%s\" /Title Cmder", icoPath); } SetEnvironmentVariable(L"CMDER_ROOT", exeDir); - SetEnvironmentVariable(L"CMDER_START", path.c_str()); + if (!streqi(path.c_str(), L"")) + { + if (!SetEnvironmentVariable(L"CMDER_START", path.c_str())) { + MessageBox(NULL, _T("Error trying to set CMDER_START to given path!"), _T("Error"), MB_OK); + } + } + else + { + wchar_t* homeProfile = 0; + SHGetKnownFolderPath(FOLDERID_Profile, 0, NULL, &homeProfile); + if (!SetEnvironmentVariable(L"CMDER_START", homeProfile)) { + MessageBox(NULL, _T("Error trying to set CMDER_START to USER_PROFILE!"), _T("Error"), MB_OK); + } + CoTaskMemFree(static_cast(homeProfile)); + } + + // Ensure EnvironmentVariables are propagated. + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL); + SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL); // For Windows >= 8 STARTUPINFO si = { 0 }; si.cb = sizeof(STARTUPINFO); @@ -149,8 +184,10 @@ void StartCmder(std::wstring path, bool is_single_mode) #endif PROCESS_INFORMATION pi; - - CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi); + if (!CreateProcess(conEmuPath, args, NULL, NULL, false, 0, NULL, NULL, &si, &pi)) { + MessageBox(NULL, _T("Unable to create the ConEmu Process!"), _T("Error"), MB_OK); + return; + } } bool IsUserOnly(std::wstring opt) diff --git a/packignore b/packignore index d72b3edc7..f17a33f53 100644 --- a/packignore +++ b/packignore @@ -16,3 +16,6 @@ icons\icon_256.png Cmder.bat vendor\tmp appveyor.yml +vendor\cmder.sh +vendor\git-prompt.sh +config\user-* diff --git a/scripts/build.ps1 b/scripts/build.ps1 index fd472e384..473cfbeb8 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -105,10 +105,26 @@ Pop-Location if($Compile) { Push-Location -Path $launcher msbuild CmderLauncher.vcxproj /p:configuration=Release + if ($LastExitCode -ne 0) { + throw "msbuild failed to build the executable." + } Pop-Location } else { Write-Warning "You are not building a launcher, Use -Compile" Write-Warning "This cannot be a release. Test build only!" } +# Put vendor\cmder.sh in /etc/profile.d so it runs when we start bash or mintty +if ( (Test-Path $($SaveTo + "git-for-windows/etc/profile.d") ) ) { + write-verbose "Adding cmder.sh /etc/profile.d" + Copy-Item $($SaveTo + "cmder.sh") $($SaveTo + "git-for-windows/etc/profile.d/cmder.sh") +} + +# Replace /etc/profile.d/git-prompt.sh with cmder lambda prompt so it runs when we start bash or mintty +if ( !(Test-Path $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak") ) ) { + write-verbose "Replacing /etc/profile.d/git-prompt.sh with our git-prompt.sh" + Move-Item $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh") $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh.bak") + Copy-Item $($SaveTo + "git-prompt.sh") $($SaveTo + "git-for-windows/etc/profile.d/git-prompt.sh") +} + Write-Verbose "All good and done!" diff --git a/config/aliases b/vendor/aliases.example similarity index 94% rename from config/aliases rename to vendor/aliases.example index 41d71ad27..c726204b1 100644 --- a/config/aliases +++ b/vendor/aliases.example @@ -5,3 +5,4 @@ pwd=cd clear=cls history=cat %CMDER_ROOT%\config\.history unalias=alias /d $1 +vi=vim $* diff --git a/config/cmder.lua b/vendor/clink.lua similarity index 90% rename from config/cmder.lua rename to vendor/clink.lua index 836540d3b..fed2baf1d 100644 --- a/config/cmder.lua +++ b/vendor/clink.lua @@ -1,3 +1,17 @@ +-- default script for clink, called by init.bat when injecting clink + +-- !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED +-- !!! Use "%CMDER_ROOT%\config\.lua" to add your lua startup scripts + + +-- At first, load the original clink.lua file +-- this is needed as we set the script path to this dir and therefore the original +-- clink.lua is not loaded. +local clink_lua_file = clink.get_env('CMDER_ROOT')..'\\vendor\\clink\\clink.lua' +dofile(clink_lua_file) + +-- now add our own things... + function lambda_prompt_filter() clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ") end @@ -142,7 +156,7 @@ end -- @return {bool} --- function get_git_status() - return os.execute("git diff --quiet --ignore-submodules HEAD 2>nul") + return io.popen("git diff --quiet --ignore-submodules HEAD 2>nul") end function git_prompt_filter() @@ -189,3 +203,4 @@ for _,lua_module in ipairs(clink.find_files(completions_dir..'*.lua')) do dofile(filename) end end + diff --git a/vendor/cmder.sh b/vendor/cmder.sh new file mode 100644 index 000000000..4d1da3ac0 --- /dev/null +++ b/vendor/cmder.sh @@ -0,0 +1,53 @@ +# DO NOT EDIT THIS FILE IT WILL BE OVERWRITTEN ON UPDATE +# +# Add portable user customizations ${CMDER_ROOT}/config/user-profile.sh, +# these customizations will follow Cmder if $CMDER_ROOT is copied +# to another machine. +# +# Add system specific users customizations to $HOME/.bashrc, these +# customizations will not follow Cmder to another machine. + +# We do this for bash as admin sessions since $CMDER_ROOT is not being set +if [ "$CMDER_ROOT" == "" ] ; then + case "$ConEmuDir" in *\\*) CMDER_ROOT=$( cd "$(cygpath -u "$ConEmuDir")/../.." ; pwd );; esac +else + case "$CMDER_ROOT" in *\\*) CMDER_ROOT="$(cygpath -u "$CMDER_ROOT")";; esac +fi + +# Remove any trailing '/' +CMDER_ROOT=$(echo $CMDER_ROOT | sed 's:/*$::') + +export CMDER_ROOT + +if [ -d "/c/Program Files/Git" ] ; then + GIT_INSTALL_ROOT="/c/Program Files/Git" +elif [ -d "/c/Program Files(x86)/Git" ] ; then + GIT_INSTALL_ROOT="/c/Program Files(x86)/Git" +elif [ -d "${CMDER_ROOT}/vendor/git-for-windows" ] ; then + GIT_INSTALL_ROOT=${CMDER_ROOT}/vendor/git-for-windows +fi + +if [[ ! "$PATH" =~ "${GIT_INSTALL_ROOT}/bin:" ]] ; then + PATH=${GIT_INSTALL_ROOT}/bin:$PATH +fi + +PATH=${CMDER_ROOT}/bin:$PATH:${CMDER_ROOT} + +export PATH + +if [ -f ${CMDER_ROOT}/config/user-profile.sh ] ; then + . ${CMDER_ROOT}/config/user-profile.sh +else + echo Creating user startup file: "${CMDER_ROOT}/config/user-profile.sh" + cat <<-eof >"${CMDER_ROOT}/config/user-profile.sh" +# use this file to run your own startup commands for msys2 bash' + +# To add a new vendor to the path, do something like: +# export PATH=\${CMDER_ROOT}/vendor/whatever:\${PATH} +eof +fi + +# Source the users .bashrc file if it exists +if [ -f "${HOME}/.bashrc" ] ; then + . "${HOME}/.bashrc" +fi diff --git a/vendor/git-prompt.sh b/vendor/git-prompt.sh new file mode 100644 index 000000000..81aedb0c4 --- /dev/null +++ b/vendor/git-prompt.sh @@ -0,0 +1,22 @@ +PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]' # set window title +PS1="$PS1"'\[\033[32m\]' # change to green +PS1="$PS1"'\u@\h ' # user@host +PS1="$PS1"'\[\033[33m\]' # change to brownish yellow +PS1="$PS1"'\w' # current working directory +if test -z "$WINELOADERNOEXEC" +then + GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)" + COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}" + COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}" + COMPLETION_PATH="$COMPLETION_PATH/share/git/completion" + if test -f "$COMPLETION_PATH/git-prompt.sh" + then + . "$COMPLETION_PATH/git-completion.bash" + . "$COMPLETION_PATH/git-prompt.sh" + PS1="$PS1"'\[\033[36m\]' # change color to cyan + PS1="$PS1"'`__git_ps1`' # bash function + fi +fi +PS1="$PS1"'\[\033[0m\]' # change color +PS1="$PS1"'\n' # new line +PS1="$PS1"'λ ' # prompt: always λ diff --git a/vendor/init.bat b/vendor/init.bat index b25b825fd..89e27c00d 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -2,13 +2,14 @@ :: Created as part of cmder project :: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED -:: !!! Use "%CMDER_ROOT%\config\user-startup.cmd" to add your own startup commands +:: !!! Use "%CMDER_ROOT%\config\user-profile.cmd" to add your own startup commands :: Find root dir @if not defined CMDER_ROOT ( for /f "delims=" %%i in ("%ConEmuDir%\..\..") do @set CMDER_ROOT=%%~fi ) +:: Remove trailing '\' @if "%CMDER_ROOT:~-1%" == "\" SET CMDER_ROOT=%CMDER_ROOT:~0,-1% :: Change the prompt style @@ -22,8 +23,14 @@ set architecture=64 ) +:: Tell the user about the clink config files... +@if not exist "%CMDER_ROOT%\config\settings" ( + echo Generating clink initial settings in %CMDER_ROOT%\config\settings + echo Additional *.lua files in %CMDER_ROOT%\config are loaded on startup. +) + :: Run clink -@"%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config" +@"%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config" --scripts "%CMDER_ROOT%\vendor" :: Prepare for git-for-windows @@ -36,6 +43,8 @@ set "GIT_INSTALL_ROOT=%ProgramFiles%\Git" ) else if exist "%ProgramFiles(x86)%\Git" ( set "GIT_INSTALL_ROOT=%ProgramFiles(x86)%\Git" +) else if exist "%USERPROFILE%\AppData\Local\Programs\Git" ( + set "GIT_INSTALL_ROOT=%USERPROFILE%\AppData\Local\Programs\Git" ) else if exist "%CMDER_ROOT%\vendor\git-for-windows" ( set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows" ) @@ -48,27 +57,42 @@ ) :: Enhance Path -@set PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\ +@set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\" + + +:: make sure we have an example file +@if not exist "%CMDER_ROOT%\config\aliases" ( + echo Creating intial aliases in %CMDER_ROOT%\config\aliases + copy "%CMDER_ROOT%\vendor\aliases.example" "%CMDER_ROOT%\config\aliases" > null +) :: Add aliases @doskey /macrofile="%CMDER_ROOT%\config\aliases" +:: See vendor\git-for-windows\README.portable for why we do this +:: Basically we need to execute this post-install.bat because we are +:: manually extracting the archive rather than executing the 7z sfx +@if exist "%CMDER_ROOT%\vendor\git-for-windows\post-install.bat" ( + echo Running Git for Windows one time Post Install.... + cd /d "%CMDER_ROOT%\vendor\git-for-windows\" + "%CMDER_ROOT%\vendor\git-for-windows\git-bash.exe" --no-needs-console --hide --no-cd --command=post-install.bat + cd /d %USERPROFILE% +) + :: Set home path @if not defined HOME set HOME=%USERPROFILE% +:: This is either a env variable set by the user or the result of +:: cmder.exe setting this variable due to a commandline argument or a "cmder here" @if defined CMDER_START ( @cd /d "%CMDER_START%" -) else ( - @if "%CD%\" == "%CMDER_ROOT%\" ( - @cd /d "%HOME%" - ) ) -@if exist "%CMDER_ROOT%\config\user-startup.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-startup.cmd" + call "%CMDER_ROOT%\config\user-profile.cmd" ) else ( - @echo Creating user startup file: "%CMDER_ROOT%\config\user-startup.cmd" + @echo Creating user startup file: "%CMDER_ROOT%\config\user-profile.cmd" ( @echo :: use this file to run your own startup commands @echo :: use @ in front of the command to prevent printing the command @@ -76,5 +100,5 @@ @echo :: @call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd @echo :: @set PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%% @echo. - ) > "%CMDER_ROOT%\config\user-startup.cmd" + ) > "%CMDER_ROOT%\config\user-profile.cmd" ) diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 1383487c7..6ed8a048a 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -4,6 +4,14 @@ # !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED # !!! Use "%CMDER_ROOT%\config\user-profile.ps1" to add your own startup commands +# We do this for Powershell as Admin Sessions because CMDER_ROOT is not beng set. +if (! $ENV:CMDER_ROOT ) { + $ENV:CMDER_ROOT = resolve-path( $ENV:ConEmuDir + "\..\.." ) +} + +# Remove trailing '\' +$ENV:CMDER_ROOT = (($ENV:CMDER_ROOT).trimend("\")) + # Compatibility with PS major versions <= 2 if(!$PSScriptRoot) { $PSScriptRoot = Split-Path $Script:MyInvocation.MyCommand.Path @@ -19,14 +27,21 @@ if( -not $env:PSModulePath.Contains($CmderModulePath) ){ try { Get-command -Name "vim" -ErrorAction Stop >$null } catch { - $env:Path += ";$env:CMDER_ROOT\vendor\git-for-windows\usr\share\vim\vim74" + # # You could do this but it may be a little drastic and introduce a lot of + # # unix tool overlap with powershel unix like aliases + # $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\usr\bin") + # set-alias -name "vi" -value "vim" + # # I think the below is safer. + + new-alias -name "vim" -value $($ENV:CMDER_ROOT + "\vendor\git-for-windows\usr\bin\vim.exe") + new-alias -name "vi" -value vim } try { # Check if git is on PATH, i.e. Git already installed on system Get-command -Name "git" -ErrorAction Stop >$null } catch { - $env:Path += ";$env:CMDER_ROOT\vendor\git-for-windows\bin" + $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin") } try { @@ -67,17 +82,16 @@ if ($gitStatus) { } # Move to the wanted location -if (Test-Path Env:\CMDER_START) { - Set-Location -Path $Env:CMDER_START -} elseif ($Env:CMDER_ROOT -and $Env:CMDER_ROOT.StartsWith($pwd)) { - Set-Location -Path $Env:USERPROFILE +# This is either a env variable set by the user or the result of +# cmder.exe setting this variable due to a commandline argument or a "cmder here" +if ( $ENV:CMDER_START ) { + Set-Location -Path "$ENV:CMDER_START" } # Enhance Path $env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT" - -$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. . "$CmderUserProfilePath" diff --git a/vendor/sources.json b/vendor/sources.json index c0e6cb62a..23c56e488 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -1,22 +1,22 @@ [ { "name": "git-for-windows", - "version": "v2.6.3.windows.1", - "url": "https://github.com/git-for-windows/git/releases/download/v2.6.3.windows.1/PortableGit-2.6.3-32-bit.7z.exe" + "version": "v2.7.0.windows.2", + "url": "https://github.com/git-for-windows/git/releases/download/v2.7.0.windows.2/PortableGit-2.7.0.2-32-bit.7z.exe" }, { "name": "clink", - "version": "0.4.5", - "url": "https://github.com/mridgers/clink/releases/download/0.4.5/clink_0.4.5.zip" + "version": "0.4.7", + "url": "https://github.com/mridgers/clink/releases/download/0.4.7/clink_0.4.7.zip" }, { "name": "conemu-maximus5", - "version": "151109", - "url": "https://github.com/Maximus5/ConEmu/releases/download/v15.11.09/ConEmuPack.151109.7z" + "version": "160202", + "url": "https://github.com/Maximus5/ConEmu/releases/download/v16.02.02/ConEmuPack.160202.7z" }, { "name": "clink-completions", - "version": "0.2.1", - "url": "https://github.com/vladimir-kotikov/clink-completions/archive/0.2.1.zip" + "version": "0.2.2", + "url": "https://github.com/vladimir-kotikov/clink-completions/archive/0.2.2.zip" } ]