diff --git a/README.md b/README.md index cdaa4d6..06acbf5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ # Cmder -[![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) +[![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/branch/master?svg=true)](https://ci.appveyor.com/project/MartiUK/cmder) Cmder is a **software package** created out of pure frustration over absence of usable console emulator on Windows. It is based on [ConEmu](https://conemu.github.io/) with *major* config overhaul, comes with a Monokai color scheme, amazing [clink](https://github.com/mridgers/clink) (further enhanced by [clink-completions](https://github.com/vladimir-kotikov/clink-completions)) and a custom prompt layout. @@ -15,9 +13,9 @@ The main advantage of Cmder is portability. It is designed to be totally self-co ## Installation 1. Download the [latest release](https://github.com/cmderdev/cmder/releases/) -2. Extract -3. (optional) Place your own executable files into the `bin` folder to be injected into your PATH. -4. Run Cmder +2. Extract the archive +3. (optional) Place your own executable files into the `bin` folder to be injected into your PATH +4. Run Cmder.exe ## Integration @@ -44,7 +42,7 @@ In a file explorer window right click in or on a directory to see "Cmder Here" i ### Shell -* Shift + Up : Traverse up in directory structure (lovely feature!) +* Ctrl + Alt + U : Traverse up in directory structure (lovely feature!) * End, Home, Ctrl : Traversing text with as usual on Windows * Ctrl + R : History search * Shift + Mouse : Select and copy text from buffer @@ -60,18 +58,18 @@ You can open multiple tabs each containing one of the following shells: |----|-----|-----------| |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.| +|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. +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/). +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://github.com/mintty/mintty). An example of setting Cmder portable terminal colors for mintty: @@ -90,7 +88,7 @@ User specific configuration is possible using the cmder specific shell config fi |Shell|Cmder Portable User Config| | ------------- |:-------------:| |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| Note: Bash and Mintty sessions will also source the '$HOME/.bashrc' file it it exists after it sources '$CMDER_ROOT/config/user-profile.sh'. @@ -101,7 +99,7 @@ You can write *.cmd|*.bat, *.ps1, and *.sh scripts and just drop them in the %CM |Shell|Cmder 'Profile.d' Scripts| | ------------- |:-------------:| |Cmder|%CMDER_ROOT%\config\profile.d\\*.bat and *.cmd| -|Powershell|$ENV:CMDER_ROOT\config\profile.d\\*.ps1| +|PowerShell|$ENV:CMDER_ROOT\config\profile.d\\*.ps1| |Bash/Mintty|$CMDER_ROOT/config/profile.d/*.sh| @@ -118,8 +116,8 @@ Bash shells support simple and complex aliases with optional parameters natively 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. +#### 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 @@ -129,11 +127,11 @@ If you want to run SSH agent on startup, include the line `@call "%GIT_INSTALL_R ### Using external Cygwin/Babun, MSys2, or Git for Windows SDK with Cmder. -1. Setup a new task by pressing 'Win +Alt + T' +1. Setup a new task by pressing 'Win +Alt + T'. 1. Click the '+' button to add a task. 1. Name the new task in the top text box. 1. Provide task parameters, this is optional. -1. Add ```cmd /c "[path_to_external_env]\bin\bash --login -i" -new_console:d:%USERPROFILE%``` to the Commands text box. +1. Add ```cmd /c "[path_to_external_env]\bin\bash --login -i" -new_console:d:%USERPROFILE%``` to the `Commands` text box. Recommended Optional Steps: @@ -152,13 +150,9 @@ Uncomment and edit the below line in the script to use Cmder config even when la # CMDER_ROOT=${USERPROFILE}/cmder # This is not required if launched from Cmder. ``` -## Todo - -1. Check for clink and git before injecting them (Sort of done) - ## Current development branch -You can download builds of the current development branch by going to Appveyor via the following link: +You can download builds of the current development branch by going to AppVeyor via the following link: [![AppVeyor](https://ci.appveyor.com/api/projects/status/github/cmderdev/cmder?svg=True)](https://ci.appveyor.com/project/MartiUK/cmder/branch/development/artifacts) @@ -168,7 +162,7 @@ All software included is bundled with own license The MIT License (MIT) -Copyright (c) 2015 Samuel Vasko +Copyright (c) 2016 Samuel Vasko Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/bin/alias.bat b/bin/alias.bat index f71a433..025b8b9 100644 --- a/bin/alias.bat +++ b/bin/alias.bat @@ -1,64 +1,131 @@ @echo off -set ALIASES=%CMDER_ROOT%\config\aliases -setlocal -:: handle quotes within command definition, e.g. quoted long file names -set _x="%*" -set _x=%_x:"=% + +if "%aliases%" == "" ( + set ALIASES=%CMDER_ROOT%\config\user-aliases.cmd +) + +setlocal enabledelayedexpansion + +if "%~1" == "" echo Use /? for help & echo. & goto :p_show :: check command usage -if ["%_x%"] == [""] echo Use /? for help & echo. & goto :p_show -if ["%1"] == ["/?"] goto:p_help -if ["%1"] == ["/reload"] goto:p_reload -:: /d flag for delete existing alias -if ["%1"] == ["/d"] goto:p_del %* -:: if arg is an existing alias, display it -if ["%2"] == [""] ( - doskey /macros | findstr /b %1= && goto:eof - echo Insufficient parameters. & goto:p_help + +rem #region parseargument +goto parseargument + +:do_shift + shift + +:parseargument + set currentarg=%~1 + + if /i "%currentarg%" equ "/f" ( + set aliases=%~2 + shift + goto :do_shift + ) else if /i "%currentarg%" == "/reload" ( + goto :p_reload + ) else if "%currentarg%" equ "/?" ( + goto :p_help + ) else if /i "%currentarg%" equ "/d" ( + if "%~2" neq "" ( + if "%~3" equ "" ( + :: /d flag for delete existing alias + call :p_del %~2 + shift + goto :eof + ) + ) + ) else if "%currentarg%" neq "" ( + if "%~2" equ "" ( + :: Show the specified alias + doskey /macros | findstr /b %currentarg%= && exit /b + echo insufficient parameters. + goto :p_help + ) else ( + :: handle quotes within command definition, e.g. quoted long file names + set _x=%* + ) + ) +rem #endregion parseargument + +if "%aliases%" neq "%CMDER_ROOT%\config\user-aliases.cmd" ( + set _x=!_x:/f %aliases% =! + + if not exist "%aliases%" ( + echo ;= @echo off>"%aliases%" + echo ;= rem Call DOSKEY and use this file as the macrofile>>"%aliases%" + echo ;= %%SystemRoot%%\system32\doskey /listsize=1000 /macrofile=%%0%%>>"%aliases%" + echo ;= rem In batch mode, jump to the end of the file>>"%aliases%" + echo ;= goto:eof>>"%aliases%" + echo ;= Add aliases below here>>"%aliases%" + ) ) :: validate alias -for /f "delims== tokens=1" %%G in ("%_x%") do set alias=%%G -set _temp=%alias: =% +for /f "delims== tokens=1,2 usebackq" %%G in (`echo "%_x%"`) do ( + set alias_name=%%G + set alias_value=%%H +) -if not ["%_temp%"] == ["%alias%"] ( +:: leading quotes added while validating +set alias_name=%alias_name:~1% + +:: trailing quotes added while validating +set alias_value=%alias_value:~0,-1% + +::remove spaces +set _temp=%alias_name: =% + +if not ["%_temp%"] == ["%alias_name%"] ( echo Your alias name can not contain a space endlocal - goto:eof + exit /b ) :: replace already defined alias -findstr /b /v /i "%alias%=" "%ALIASES%" >> "%ALIASES%.tmp" -echo %* >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp" +findstr /b /v /i "%alias_name%=" "%ALIASES%" >> "%ALIASES%.tmp" +echo %alias_name%=%alias_value% >> "%ALIASES%.tmp" && type "%ALIASES%.tmp" > "%ALIASES%" & @del /f /q "%ALIASES%.tmp" doskey /macrofile="%ALIASES%" endlocal -goto:eof +exit /b :p_del -findstr /b /v /i "%2=" "%ALIASES%" >> "%ALIASES%.tmp" +set del_alias=%~1 +findstr /b /v /i "%del_alias%=" "%ALIASES%" >> "%ALIASES%.tmp" type "%ALIASES%".tmp > "%ALIASES%" & @del /f /q "%ALIASES%.tmp" +doskey %del_alias%= doskey /macrofile=%ALIASES% goto:eof :p_reload doskey /macrofile="%ALIASES%" echo Aliases reloaded -goto:eof +exit /b :p_show -type "%ALIASES%" || echo No aliases found at "%ALIASES%" -goto :eof +doskey /macros|findstr /v /r "^;=" | sort +exit /b :p_help echo.Usage: -echo. alias [/reload] [/d] [name=full command] -echo. /reload Reload the aliases file -echo. /d Delete an alias (must be followed by the alias name) +echo. +echo. alias [options] [alias=full command] +echo. +echo.Options: +echo. +echo. /d [alias] Delete an [alias]. +echo. /f [macrofile] Path to the [macrofile] you want to store the new alias in. +echo. Default: %cmder_root%\config\user-aliases.cmd +echo. /reload Reload the aliases file. Can be used with /f argument. +echo. Default: %cmder_root%\config\user-aliases.cmd +echo. +echo. If alias is called with no parameters, it will display the list of existing aliases. echo. -echo. If alias is called with any parameters, it will display the list of existing aliases. echo. In the command, you can use the following notations: echo. $* allows the alias to assume all the parameters of the supplied command. echo. $1-$9 Allows you to seperate parameter by number, much like %%1 in batch. echo. $T is the command seperator, allowing you to string several commands together into one alias. echo. For more information, read DOSKEY/? +exit /b diff --git a/icons/cmder_blue.ico b/icons/cmder_blue.ico new file mode 100644 index 0000000..acdcb8a Binary files /dev/null and b/icons/cmder_blue.ico differ diff --git a/icons/cmder_green.ico b/icons/cmder_green.ico new file mode 100644 index 0000000..f111b4c Binary files /dev/null and b/icons/cmder_green.ico differ diff --git a/icons/cmder_icon.psd b/icons/cmder_icon.psd index 44e5d7a..0c41c6c 100644 Binary files a/icons/cmder_icon.psd and b/icons/cmder_icon.psd differ diff --git a/icons/cmder_orange.ico b/icons/cmder_orange.ico new file mode 100644 index 0000000..6385bbc Binary files /dev/null and b/icons/cmder_orange.ico differ diff --git a/icons/cmder_purple.ico b/icons/cmder_purple.ico new file mode 100644 index 0000000..1d2dbfe Binary files /dev/null and b/icons/cmder_purple.ico differ diff --git a/icons/cmder_red.ico b/icons/cmder_red.ico new file mode 100644 index 0000000..f06255c Binary files /dev/null and b/icons/cmder_red.ico differ diff --git a/icons/cmder_yellow.ico b/icons/cmder_yellow.ico new file mode 100644 index 0000000..c909650 Binary files /dev/null and b/icons/cmder_yellow.ico differ diff --git a/icons/icon_16_blue.png b/icons/icon_16_blue.png new file mode 100644 index 0000000..6fd39b5 Binary files /dev/null and b/icons/icon_16_blue.png differ diff --git a/icons/icon_16_green.png b/icons/icon_16_green.png new file mode 100644 index 0000000..5412344 Binary files /dev/null and b/icons/icon_16_green.png differ diff --git a/icons/icon_16_orange.png b/icons/icon_16_orange.png new file mode 100644 index 0000000..63a739c Binary files /dev/null and b/icons/icon_16_orange.png differ diff --git a/icons/icon_16_purple.png b/icons/icon_16_purple.png new file mode 100644 index 0000000..6509e88 Binary files /dev/null and b/icons/icon_16_purple.png differ diff --git a/icons/icon_16_red.png b/icons/icon_16_red.png new file mode 100644 index 0000000..b440572 Binary files /dev/null and b/icons/icon_16_red.png differ diff --git a/icons/icon_16_yellow.png b/icons/icon_16_yellow.png new file mode 100644 index 0000000..e604352 Binary files /dev/null and b/icons/icon_16_yellow.png differ diff --git a/icons/icon_256_blue.png b/icons/icon_256_blue.png new file mode 100644 index 0000000..774f130 Binary files /dev/null and b/icons/icon_256_blue.png differ diff --git a/icons/icon_256_green.png b/icons/icon_256_green.png new file mode 100644 index 0000000..a41850c Binary files /dev/null and b/icons/icon_256_green.png differ diff --git a/icons/icon_256_orange.png b/icons/icon_256_orange.png new file mode 100644 index 0000000..f76e404 Binary files /dev/null and b/icons/icon_256_orange.png differ diff --git a/icons/icon_256_purple.png b/icons/icon_256_purple.png new file mode 100644 index 0000000..7e61809 Binary files /dev/null and b/icons/icon_256_purple.png differ diff --git a/icons/icon_256_red.png b/icons/icon_256_red.png new file mode 100644 index 0000000..128adad Binary files /dev/null and b/icons/icon_256_red.png differ diff --git a/icons/icon_256_yellow.png b/icons/icon_256_yellow.png new file mode 100644 index 0000000..37a7246 Binary files /dev/null and b/icons/icon_256_yellow.png differ diff --git a/icons/icon_32_blue.png b/icons/icon_32_blue.png new file mode 100644 index 0000000..0e5116d Binary files /dev/null and b/icons/icon_32_blue.png differ diff --git a/icons/icon_32_green.png b/icons/icon_32_green.png new file mode 100644 index 0000000..016f66a Binary files /dev/null and b/icons/icon_32_green.png differ diff --git a/icons/icon_32_orange.png b/icons/icon_32_orange.png new file mode 100644 index 0000000..bb01e97 Binary files /dev/null and b/icons/icon_32_orange.png differ diff --git a/icons/icon_32_purple.png b/icons/icon_32_purple.png new file mode 100644 index 0000000..ba8d82a Binary files /dev/null and b/icons/icon_32_purple.png differ diff --git a/icons/icon_32_red.png b/icons/icon_32_red.png new file mode 100644 index 0000000..7c75e0e Binary files /dev/null and b/icons/icon_32_red.png differ diff --git a/icons/icon_32_yellow.png b/icons/icon_32_yellow.png new file mode 100644 index 0000000..9056e48 Binary files /dev/null and b/icons/icon_32_yellow.png differ diff --git a/icons/icon_48_blue.png b/icons/icon_48_blue.png new file mode 100644 index 0000000..e5b71d3 Binary files /dev/null and b/icons/icon_48_blue.png differ diff --git a/icons/icon_48_green.png b/icons/icon_48_green.png new file mode 100644 index 0000000..7233bc6 Binary files /dev/null and b/icons/icon_48_green.png differ diff --git a/icons/icon_48_orange.png b/icons/icon_48_orange.png new file mode 100644 index 0000000..0b70250 Binary files /dev/null and b/icons/icon_48_orange.png differ diff --git a/icons/icon_48_purple.png b/icons/icon_48_purple.png new file mode 100644 index 0000000..dd61ee4 Binary files /dev/null and b/icons/icon_48_purple.png differ diff --git a/icons/icon_48_red.png b/icons/icon_48_red.png new file mode 100644 index 0000000..7562fd0 Binary files /dev/null and b/icons/icon_48_red.png differ diff --git a/icons/icon_48_yellow.png b/icons/icon_48_yellow.png new file mode 100644 index 0000000..d78225d Binary files /dev/null and b/icons/icon_48_yellow.png differ diff --git a/launcher/src/CmderLauncher.cpp b/launcher/src/CmderLauncher.cpp index b2b0ffa..24f35c8 100644 --- a/launcher/src/CmderLauncher.cpp +++ b/launcher/src/CmderLauncher.cpp @@ -131,7 +131,14 @@ void StartCmder(std::wstring path, bool is_single_mode) PathCombine(cfgPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.xml"); } - PathCombine(conEmuPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.exe"); + SYSTEM_INFO sysInfo; + GetNativeSystemInfo(&sysInfo); + if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { + PathCombine(conEmuPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu64.exe"); + } + else { + PathCombine(conEmuPath, exeDir, L"vendor\\conemu-maximus5\\ConEmu.exe"); + } if (FileExists(oldCfgPath) && !FileExists(cfgPath)) { diff --git a/packignore b/packignore index f17a33f..ead3d89 100644 --- a/packignore +++ b/packignore @@ -9,10 +9,10 @@ config\.history packignore icons\Thumbs.db icons\cmder_icon.psd -icons\icon_16.png -icons\icon_32.png -icons\icon_48.png -icons\icon_256.png +icons\icon_16*.png +icons\icon_32*.png +icons\icon_48*.png +icons\icon_256*.png Cmder.bat vendor\tmp appveyor.yml diff --git a/scripts/utils.ps1 b/scripts/utils.ps1 index 9c5679a..cf7fe7b 100644 --- a/scripts/utils.ps1 +++ b/scripts/utils.ps1 @@ -28,7 +28,7 @@ function Delete-Existing ($path) { } function Extract-Archive ($source, $target) { - Invoke-Expression "7z x -y -o$($target) '$source' > `$null" + Invoke-Expression "7z x -y -o`"$($target)`" `"$source`" > `$null" if ($lastexitcode -ne 0) { Write-Error "Extracting of $source failied" } @@ -79,14 +79,39 @@ function Register-Cmder(){ ) Begin { - New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT + New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT > $null } Process { - New-Item -Path "HKCR:\Directory\Shell\Cmder" -Force -Value $MenuText + New-Item -Path "HKCR:\Directory\Shell\Cmder" -Force -Value $MenuText New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`" New-ItemProperty -Path "HKCR:\Directory\Shell\Cmder" -Force -Name "NoWorkingDirectory" - New-Item -Path "HKCR:\Directory\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" " + New-Item -Path "HKCR:\Directory\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" " + + New-Item -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Value $MenuText + New-ItemProperty -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Name "Icon" -Value `"$icon`" + New-ItemProperty -Path "HKCR:\Directory\Background\Shell\Cmder" -Force -Name "NoWorkingDirectory" + New-Item -Path "HKCR:\Directory\Background\Shell\Cmder\Command" -Force -Value "`"$PathToExe`" `"$Command`" " + } + End + { + Remove-PSDrive -Name HKCR + } +} + +function Unregister-Cmder{ + Begin + { + New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT > $null + } + Process + { + Remove-Item -Path "HKCR:\Directory\Shell\Cmder" -Recurse + Remove-Item -Path "HKCR:\Directory\Background\Shell\Cmder" -Recurse + } + End + { + Remove-PSDrive -Name HKCR } } @@ -99,6 +124,9 @@ function Download-File { $File = $File -Replace "/", "\" Write-Verbose "Downloading from $Url to $File" $wc = new-object System.Net.WebClient - $wc.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials; + if ($env:https_proxy) { + $wc.proxy = (new-object System.Net.WebProxy($env:https_proxy)) + } + $wc.Proxy.Credentials=[System.Net.CredentialCache]::DefaultNetworkCredentials; $wc.DownloadFile($Url, $File) } diff --git a/vendor/aliases.example b/vendor/aliases.example deleted file mode 100644 index c726204..0000000 --- a/vendor/aliases.example +++ /dev/null @@ -1,8 +0,0 @@ -e.=explorer . -gl=git log --oneline --all --graph --decorate $* -ls=ls --show-control-chars -F --color $* -pwd=cd -clear=cls -history=cat %CMDER_ROOT%\config\.history -unalias=alias /d $1 -vi=vim $* diff --git a/vendor/clink.lua b/vendor/clink.lua index b6f0059..11e6433 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -12,8 +12,18 @@ dofile(clink_lua_file) -- now add our own things... -function lambda_prompt_filter() - clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ") +--- + -- Setting the prompt in clink means that commands which rewrite the prompt do + -- not destroy our own prompt. It also means that started cmds (or batch files + -- which echo) don't get the ugly '{lamb}' shown. +--- +function set_prompt_filter() + -- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m + -- color codes: "\x1b[1;37;40m" + cwd = clink.get_cwd() + prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m" + new_value = string.gsub(prompt, "{cwd}", cwd) + clink.prompt.value = string.gsub(new_value, "{lamb}", "λ") end --- @@ -193,7 +203,10 @@ end -- @return {bool} --- function get_git_status() - return io.popen("git diff --quiet --ignore-submodules HEAD 2>nul") + for line in io.popen("git status --porcelain 2>nul"):lines() do + return false + end + return true end function git_prompt_filter() @@ -226,7 +239,8 @@ function git_prompt_filter() return false end -clink.prompt.register_filter(lambda_prompt_filter, 40) +-- insert the set_prompt at the very beginning so that it runs first +clink.prompt.register_filter(set_prompt_filter, 1) clink.prompt.register_filter(hg_prompt_filter, 50) clink.prompt.register_filter(git_prompt_filter, 50) diff --git a/vendor/init.bat b/vendor/init.bat index 4fc232c..730efea 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -6,17 +6,16 @@ :: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED :: !!! Use "%CMDER_ROOT%\config\user-profile.cmd" to add your own startup commands +:: Set to > 0 for verbose output to aid in debugging. +if not defined verbose-output ( set verbose-output=0 ) + :: Find root dir if not defined CMDER_ROOT ( - for /f "delims=" %%i in ("%ConEmuDir%\..\..") do set CMDER_ROOT=%%~fi + 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 -:: Mmm tasty lamb -prompt $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m +if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%" :: Pick right version of clink if "%PROCESSOR_ARCHITECTURE%"=="x86" ( @@ -27,9 +26,9 @@ if "%PROCESSOR_ARCHITECTURE%"=="x86" ( :: 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. -) + 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" --scripts "%CMDER_ROOT%\vendor" @@ -40,24 +39,55 @@ if not exist "%CMDER_ROOT%\config\settings" ( set PLINK_PROTOCOL=ssh if not defined TERM set TERM=cygwin -:: Check if msysgit is installed -if exist "%ProgramFiles%\Git" ( - 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" +:: The idea: +:: * if the users points as to a specific git, use that +:: * test if a git is in path and if yes, use that +:: * last, use our vendored git +:: also check that we have a recent enough version of git (e.g. test for GIT\cmd\git.exe) +if defined GIT_INSTALL_ROOT ( + if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (goto :FOUND_GIT) ) +:: check if git is in path... +setlocal enabledelayedexpansion +for /F "delims=" %%F in ('where git.exe 2^>nul') do @( + pushd %%~dpF + cd .. + set "test_dir=!CD!" + popd + if exist "!test_dir!\cmd\git.exe" ( + set "GIT_INSTALL_ROOT=!test_dir!" + set test_dir= + goto :FOUND_GIT + ) else ( + echo Found old git version in "!test_dir!", but not using... + set test_dir= + ) +) + +:: our last hope: our own git... +:VENDORED_GIT +if exist "%CMDER_ROOT%\vendor\git-for-windows" ( + set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows" + call :verbose-output Add the minimal git commands to the front of the path + set "PATH=!GIT_INSTALL_ROOT!\cmd;%PATH%" +) else ( + goto :NO_GIT +) + +:FOUND_GIT :: Add git to the path if defined GIT_INSTALL_ROOT ( - set "PATH=%GIT_INSTALL_ROOT%\bin;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74;%PATH%" + rem add the unix commands at the end to not shadow windows commands like more + call :verbose-output Enhancing PATH with unix commands from git in "%GIT_INSTALL_ROOT%\usr\bin" + set "PATH=%PATH%;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74" :: define SVN_SSH so we can use git svn with ssh svn repositories if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe" ) +:NO_GIT +endlocal & set "PATH=%PATH%" & set "SVN_SSH=%SVN_SSH%" & set "GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%" + :: Enhance Path set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\" @@ -69,32 +99,63 @@ if not exist "%CMDER_ROOT%\config\profile.d" ( pushd "%CMDER_ROOT%\config\profile.d" for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do ( - REM echo Calling %CMDER_ROOT%\config\profile.d\%%x... + call :verbose-output Calling "%CMDER_ROOT%\config\profile.d\%%x"... call "%CMDER_ROOT%\config\profile.d\%%x" ) popd -:: 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 +:: Allows user to override default aliases store using profile.d +:: scripts run above by setting the 'aliases' env variable. +:: +:: Note: If overriding default aliases store file the aliases +:: must also be self executing, see '.\user-aliases.cmd.example', +:: and be in profile.d folder. +set "user-aliases=%CMDER_ROOT%\config\user-aliases.cmd" + +:: The aliases environment variable is used by alias.bat to id +:: the default file to store new aliases in. +if not defined aliases ( + set "aliases=%user-aliases%" ) -:: Add aliases -doskey /macrofile="%CMDER_ROOT%\config\aliases" +:: Make sure we have a self-extracting user-aliases.cmd file +setlocal enabledelayedexpansion +if not exist "%user-aliases%" ( + echo Creating intial user-aliases store in "%user-aliases%"... + copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%" +) else ( + type "%user-aliases%" | findstr /i ";= Add aliases below here" >nul + if "!errorlevel!" == "1" ( + echo Creating intial user-aliases store in "%user-aliases%"... + copy "%CMDER_ROOT%\%user-aliases%" "%user-aliases%.old_format" + copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%" + ) +) + +:: Update old 'user-aliases' to new self executing 'user-aliases.cmd' +if exist "%CMDER_ROOT%\config\aliases" ( + echo Updating old "%CMDER_ROOT%\config\aliases" to new format... + type "%CMDER_ROOT%\config\aliases" >> "%user-aliases%" && del "%CMDER_ROOT%\config\aliases" +) else if exist "%user-aliases%.old_format" ( + echo Updating old "%user-aliases%" to new format... + type "%user-aliases%.old_format" >> "%user-aliases%" && del "%user-aliases%.old_format" +) +endlocal +:: Add aliases to the environment +call "%user-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.... + call :verbose-output 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% +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" @@ -102,8 +163,9 @@ if defined CMDER_START ( cd /d "%CMDER_START%" ) + 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" ) else ( echo Creating user startup file: "%CMDER_ROOT%\config\user-profile.cmd" @@ -111,8 +173,17 @@ if exist "%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 echo. - echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd - echo :: set PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%% + echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd" + echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%" echo. ) > "%CMDER_ROOT%\config\user-profile.cmd" ) + +exit /b + +:: +:: sub-routines below here +:: +:verbose-output + if %verbose-output% gtr 0 echo %* + exit /b diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 0d830f5..a2f75b5 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -41,6 +41,8 @@ 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\cmd") + # for bash.exe, which in the cmd version is found as \usr\bin\bash.exe $env:Path += $(";" + $env:CMDER_ROOT + "\vendor\git-for-windows\bin") } diff --git a/vendor/sources.json b/vendor/sources.json index 3a63b22..d027113 100644 --- a/vendor/sources.json +++ b/vendor/sources.json @@ -1,22 +1,22 @@ [ { "name": "git-for-windows", - "version": "v2.7.4.windows.1", - "url": "https://github.com/git-for-windows/git/releases/download/v2.7.4.windows.1/PortableGit-2.7.4-32-bit.7z.exe" + "version": "v2.9.0.windows.1", + "url": "https://github.com/git-for-windows/git/releases/download/v2.9.0.windows.1/PortableGit-2.9.0-32-bit.7z.exe" }, { "name": "clink", - "version": "0.4.7", - "url": "https://github.com/mridgers/clink/releases/download/0.4.7/clink_0.4.7.zip" + "version": "0.4.8", + "url": "https://github.com/mridgers/clink/releases/download/0.4.8/clink_0.4.8.zip" }, { "name": "conemu-maximus5", - "version": "160207", - "url": "https://github.com/Maximus5/ConEmu/releases/download/v16.02.07/ConEmuPack.160207.7z" + "version": "160612", + "url": "https://github.com/Maximus5/ConEmu/releases/download/v16.06.12/ConEmuPack.160612.7z" }, { "name": "clink-completions", - "version": "0.2.2", - "url": "https://github.com/vladimir-kotikov/clink-completions/archive/0.2.2.zip" + "version": "0.3.1", + "url": "https://github.com/vladimir-kotikov/clink-completions/archive/0.3.1.zip" } ] diff --git a/vendor/user-aliases.cmd.example b/vendor/user-aliases.cmd.example new file mode 100644 index 0000000..01df318 --- /dev/null +++ b/vendor/user-aliases.cmd.example @@ -0,0 +1,15 @@ +;= @echo off +;= rem Call DOSKEY and use this file as the macrofile +;= %SystemRoot%\system32\doskey /listsize=1000 /macrofile=%0% +;= rem In batch mode, jump to the end of the file +;= goto:eof +;= Add aliases below here +e.=explorer . +gl=git log --oneline --all --graph --decorate $* +ls=ls --show-control-chars -F --color $* +pwd=cd +clear=cls +history=cat %CMDER_ROOT%\config\.history +unalias=alias /d $1 +vi=vim $* +cmderr=cd /d "%CMDER_ROOT%"