Merge branch 'development' into cmder_exinit

This commit is contained in:
Dax T. Games 2016-02-19 10:10:12 -06:00
commit a99d27a7e1
11 changed files with 177 additions and 131 deletions

View File

@ -1,6 +1,6 @@
# Cmder
[![Join the chat at https://gitter.im/bliker/cmder](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cmderdev/cmder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Join the chat at https://gitter.im/cmderdev/cmder](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/cmderdev/cmder?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
![Build Status](https://ci.appveyor.com/api/projects/status/32r7s2skrgm9ubva?retina=true)
@ -10,7 +10,7 @@ Cmder is a **software package** created out of pure frustration over absence of
## Why use it
The main advantage of Cmder is portability. It is designed to be totally self-contained with no external dependencies, that is makes it great for **USB Sticks** or **cloud storage**. So you can carry your console, aliases and binaries (like wget, curl and git) with you anywhere.
The main advantage of Cmder is portability. It is designed to be totally self-contained with no external dependencies, which makes it great for **USB Sticks** or **cloud storage**. So you can carry your console, aliases and binaries (like wget, curl and git) with you anywhere.
## Installation
@ -49,16 +49,23 @@ In a file explorer window right click in or on a directory to see "Cmder Here" i
* <kbd>Ctrl</kbd> + <kbd>R</kbd> : History search
* <kbd>Shift</kbd> + Mouse : Select and copy text from buffer
(Some shortcuts are not yet documented, thought they exist, please add them here)
(Some shortcuts are not yet documented, though they exist - please document them here)
## Features
### Access to multiple shells in one window using tabs
You can open multiple tabs each containing one of the following shells:
* Cmder | Cmder as Admin - Enhanced Windows 'cmd.exe' shell.
* Powershell | Powershell as Admin - Enhanced Windows Powershell.
* Bash/mintty | Bash/mintty as Admin - Unix/Linux like bash shell running on Windows.
|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.
@ -74,30 +81,41 @@ 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-cmder.sh
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:
* Cmder - %CMDER_ROOT%\config\user-startup.cmd
* Powershell - $ENV:CMDER_ROOT\config\user-profile.ps1
* Bash/Mintty - $CMDER_ROOT/config/user-cmder.sh
|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|
Bash and Mintty sessions will also source the '$HOME/.bashrc' file it it exists before it sources '$CMDER_ROOT/config/user-cmder.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`.
For example there is one defined for you `alias e.=explorer .`
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'
All aliases will be saved in `/config/aliases` file
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`.
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.
#### 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

View File

@ -10,9 +10,6 @@ branches:
except:
- gh-pages
# Do not build on tags
skip_tags: true
#---------------------------------#
# environment configuration #
#---------------------------------#

View File

@ -123,14 +123,14 @@
<value name="ColorKeyTransparent" type="hex" data="00"/>
<value name="ColorKeyValue" type="dword" data="00010101"/>
<value name="UseCurrentSizePos" type="hex" data="01"/>
<value name="WindowMode" type="dword" data="00000520"/>
<value name="ConWnd Width" type="dword" data="0000006f"/>
<value name="ConWnd Height" type="dword" data="0000001a"/>
<value name="WindowMode" type="dword" data="0000051f"/>
<value name="ConWnd Width" type="dword" data="00000078"/>
<value name="ConWnd Height" type="dword" data="0000001e"/>
<value name="Cascaded" type="hex" data="01"/>
<value name="ConWnd X" type="dword" data="000000c5"/>
<value name="ConWnd Y" type="dword" data="00000089"/>
<value name="ConWnd X" type="dword" data="000001f4"/>
<value name="ConWnd Y" type="dword" data="000001f4"/>
<value name="16bit Height" type="dword" data="00000000"/>
<value name="AutoSaveSizePos" type="hex" data="00"/>
<value name="AutoSaveSizePos" type="hex" data="01"/>
<value name="IntegralSize" type="hex" data="00"/>
<value name="QuakeStyle" type="hex" data="00"/>
<value name="QuakeAnimation" type="dword" data="0000012c"/>
@ -527,7 +527,7 @@
<value name="Flags" type="dword" data="00000000"/>
<value name="Hotkey" type="dword" data="00000000"/>
<value name="GuiArgs" type="string" data="/icon &quot;%ConEmuDir%\..\git-for-windows\usr\share\git\git-for-windows.ico&quot;"/>
<value name="Cmd1" type="string" data="*%ConEmuDir%\..\git-for-windows\usr\bin\mintty.exe /bin/bash -l -new_console:d:%userProfile%"/>
<value name="Cmd1" type="string" data="*%ConEmuDir%\..\git-for-windows\usr\bin\mintty.exe /bin/bash -l -new_console:d:%USERPROFILE%"/>
<value name="Active" type="dword" data="00000000"/>
<value name="Count" type="dword" data="00000001"/>
</key>

View File

@ -1,3 +1,14 @@
## Config
All config files must be in this folder. If there is no option to set this folder directly, it has to 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

View File

@ -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

View File

@ -3,6 +3,8 @@
#include <Shlwapi.h>
#include "resource.h"
#include <vector>
#include <Shlobj.h>
#pragma comment(lib, "Shlwapi.lib")
@ -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");
// 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))
@ -139,20 +156,24 @@ void StartCmder(std::wstring path, bool is_single_mode)
}
SetEnvironmentVariable(L"CMDER_ROOT", exeDir);
//SetEnvironmentVariable(L"CMDER_START", path.c_str());
// Send out the Settings Changed message - Once using ANSII...
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM)"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
// ...and once using UniCode (because Windows 8 likes it that way).
//SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, (LPARAM) L"Environment", SMTO_ABORTIFHUNG, 5000, NULL);
HKEY cmderStartRegistryKey;
if (RegCreateKeyEx(HKEY_CURRENT_USER, L"Software\\cmder", 0, NULL, 0, KEY_ALL_ACCESS, NULL, &cmderStartRegistryKey, 0) == ERROR_SUCCESS)
if (streqi(path.c_str(), L""))
{
RegSetValueEx(cmderStartRegistryKey, L"CMDER_START", 0, REG_SZ, (const BYTE*) path.c_str(), path.size() * 2);
RegCloseKey(cmderStartRegistryKey);
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 given path!"), _T("Error"), MB_OK);
}
CoTaskMemFree(static_cast<void*>(homeProfile));
}
else
{
if (!SetEnvironmentVariable(L"CMDER_START", path.c_str())) {
MessageBox(NULL, _T("Error trying to set CMDER_START to given path!"), _T("Error"), MB_OK);
}
}
// 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);
@ -162,8 +183,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)

View File

@ -105,6 +105,9 @@ 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"

View File

@ -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\<whatever>.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
@ -57,8 +71,45 @@ local function get_hg_dir(path)
return get_dir_contains(path, '.hg')
end
-- adapted from from clink-completions' git.lua
local function get_git_dir(path)
return get_dir_contains(path, '.git')
-- return parent path for specified entry (either file or directory)
local function pathname(path)
local prefix = ""
local i = path:find("[\\/:][^\\/:]*$")
if i then
prefix = path:sub(1, i-1)
end
return prefix
end
-- Checks if provided directory contains git directory
local function has_git_dir(dir)
return #clink.find_dirs(dir..'/.git') > 0 and dir..'/.git'
end
local function has_git_file(dir)
local gitfile = io.open(dir..'/.git')
if not gitfile then return false end
local git_dir = gitfile:read():match('gitdir: (.*)')
gitfile:close()
return git_dir and dir..'/'..git_dir
end
-- Set default path to current directory
if not path or path == '.' then path = clink.get_cwd() end
-- Calculate parent path now otherwise we won't be
-- able to do that inside of logical operator
local parent_path = pathname(path)
return has_git_dir(path)
or has_git_file(path)
-- Otherwise go up one level and make a recursive call
or (parent_path ~= path and get_git_dir(parent_path) or nil)
end
---
@ -142,7 +193,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 +240,4 @@ for _,lua_module in ipairs(clink.find_files(completions_dir..'*.lua')) do
dofile(filename)
end
end

16
vendor/init.bat vendored
View File

@ -23,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
@ -51,7 +57,7 @@
)
:: 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
@ -76,12 +82,10 @@
:: 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-profile.cmd" (

29
vendor/profile.ps1 vendored
View File

@ -53,7 +53,7 @@ try {
}
function checkGit($Path) {
if (Test-Path -Path (Join-Path $Path '.git/') ) {
if (Test-Path -Path (Join-Path $Path '.git') ) {
Write-VcsStatus
return
}
@ -82,34 +82,15 @@ if ($gitStatus) {
}
# Move to the wanted location
$cmderStartKey = 'HKCU:\Software\cmder'
$cmderStartSubKey = 'CMDER_START'
$cmderStart = (Get-Item -Path $cmderStartKey -ErrorAction SilentlyContinue)
if ( $cmderStart ) {
$cmderStart = $cmderStart.GetValue($cmderStartSubKey)
$cmderStart = ($cmderStart).Trim('"').Trim("'")
if ( $cmderStart.EndsWith(':') ) {
$cmderStart += '\'
# 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"
}
if ( ( Get-Item $cmderStart -Force ) -is [System.IO.FileInfo] ) {
$cmderStart = Split-Path $cmderStart
}
Set-Location -Path "${cmderStart}"
Set-ItemProperty -Path $cmderStartKey -Name $cmderStartSubKey -Value $null
} else {
Set-Location -Path "${env:HOME}"
}
# Enhance Path
$env:Path = "$Env:CMDER_ROOT\bin;$env:Path;$Env:CMDER_ROOT"
$CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user-profile.ps1"
if(Test-Path $CmderUserProfilePath) {
# Create this file and place your own command in there.

16
vendor/sources.json vendored
View File

@ -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.1.windows.1",
"url": "https://github.com/git-for-windows/git/releases/download/v2.7.1.windows.1/PortableGit-2.7.1-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": "151119",
"url": "https://github.com/Maximus5/ConEmu/releases/download/v15.11.19/ConEmuPack.151119.7z"
"version": "160207",
"url": "https://github.com/Maximus5/ConEmu/releases/download/v16.02.07/ConEmuPack.160207.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"
}
]