Merge branch 'master' of github.com:cmderdev/cmder into git_clink_changes

This commit is contained in:
Dax T. Games
2019-02-28 18:03:58 -05:00
19 changed files with 580 additions and 243 deletions

View File

@ -40,7 +40,7 @@ goto parseargument
) else if "%currentarg%" neq "" (
if "%~2" equ "" (
:: Show the specified alias
doskey /macros | findstr /b %currentarg%= && exit /b
doskey /macros | %WINDIR%\System32\findstr /b %currentarg%= && exit /b
echo insufficient parameters.
goto :p_help
) else (
@ -85,7 +85,7 @@ if not ["%_temp%"] == ["%alias_name%"] (
)
:: replace already defined alias
findstr /b /v /i "%alias_name%=" "%ALIASES%" >> "%ALIASES%.tmp"
%WINDIR%\System32\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
@ -93,7 +93,7 @@ exit /b
:p_del
set del_alias=%~1
findstr /b /v /i "%del_alias%=" "%ALIASES%" >> "%ALIASES%.tmp"
%WINDIR%\System32\findstr /b /v /i "%del_alias%=" "%ALIASES%" >> "%ALIASES%.tmp"
type "%ALIASES%".tmp > "%ALIASES%" & @del /f /q "%ALIASES%.tmp"
doskey %del_alias%=
doskey /macrofile="%ALIASES%"
@ -105,7 +105,7 @@ echo Aliases reloaded
exit /b
:p_show
doskey /macros|findstr /v /r "^;=" | sort
doskey /macros|%WINDIR%\System32\findstr /v /r "^;=" | sort
exit /b
:p_help

View File

@ -52,7 +52,7 @@ set "feFlagName=%feFlagName% "
:: echo %feCommand%
:: echo %feParam%
:: echo.
echo %CMDER_USER_FLAGS% | find /i "%feFlagName%">nul
echo %CMDER_USER_FLAGS% | %WINDIR%\System32\find /i "%feFlagName%">nul
if "%ERRORLEVEL%" == "0" (
if "%feNOT%" == "false" (
endlocal && call %feCommand% %feParam%

39
vendor/clink.lua vendored
View File

@ -13,6 +13,14 @@ dofile(clink_lua_file)
-- now add our own things...
---
-- Makes a string safe to use as the replacement in string.gsub
---
local function verbatim(s)
s = string.gsub(s, "%%", "%%%%")
return s
end
---
-- 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
@ -41,13 +49,12 @@ local function set_prompt_filter()
-- color codes: "\x1b[1;37;40m"
local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg}{svn} \n\x1b[1;39;40m{lamb} \x1b[0m"
local lambda = "λ"
cwd = string.gsub(cwd, "%%", "{percent}")
cmder_prompt = string.gsub(cmder_prompt, "{cwd}", cwd)
cmder_prompt = string.gsub(cmder_prompt, "{cwd}", verbatim(cwd))
if env ~= nil then
lambda = "("..env..") "..lambda
end
clink.prompt.value = string.gsub(cmder_prompt, "{lamb}", lambda)
clink.prompt.value = string.gsub(cmder_prompt, "{lamb}", verbatim(lambda))
end
local function percent_prompt_filter()
@ -295,7 +302,7 @@ local function git_prompt_filter()
color = colors.conflict
end
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")")
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..verbatim(branch)..")")
return false
end
end
@ -317,15 +324,19 @@ local function hg_prompt_filter()
dirty = "\x1b[31;1m",
}
-- 'hg id' gives us BOTH the branch name AND an indicator that there
-- are uncommitted changes, in one fast(er) call
local pipe = io.popen("hg id 2>&1")
-- 'hg id -ib' gives us BOTH the branch name AND an indicator that there
-- are uncommitted changes, in one fast(er) call compared to "hg status"
local pipe = io.popen("hg id -ib 2>&1")
local output = pipe:read('*all')
local rc = { pipe:close() }
-- strip the trailing newline from the branch name
local n = #output
while n > 0 and output:find("^%s", n) do n = n - 1 end
output = output:sub(1, n)
if output ~= nil and
string.sub(output,1,7) ~= "abort: " and -- not an HG working copy
string.sub(output,1,12) ~= "000000000000" and -- empty wc (needs update)
(not string.find(output, "is not recognized")) then -- 'hg' not in path
local color = colors.clean
-- split elements on space delimiter
@ -335,12 +346,16 @@ local function hg_prompt_filter()
end
-- if the repo hash ends with '+', the wc has uncommitted changes
if string.sub(items[1], -1, -1) == "+" then color = colors.dirty end
-- substitute the branch in directly -- already WITH parentheses. :)
result = color .. items[2] -- string.sub(items[2], 1, string.len(items[2]) - 1)
-- substitute the branch in directly
if items[2] ~= nil then
result = color .. "(" .. items[2] .. ")"
else
result = color .. "*"
end
end
end
clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", result)
clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", verbatim(result))
return false
end
@ -362,7 +377,7 @@ local function svn_prompt_filter()
color = colors.dirty
end
clink.prompt.value = string.gsub(clink.prompt.value, "{svn}", color.."("..branch..")")
clink.prompt.value = string.gsub(clink.prompt.value, "{svn}", color.."("..verbatim(branch)..")")
return false
end
end

7
vendor/cmder.sh vendored
View File

@ -90,12 +90,7 @@ fi
if [ ! -f "${CmderUserProfilePath}" ] ; then
echo Creating user startup file: "${CmderUserProfilePath}"
cat <<-eof >"${CmderUserProfilePath}"
# use this file to run your own startup commands for msys2 bash'
# To add a new vendor to the path, do something like:
# export PATH=\${CMDER_ROOT}/vendor/whatever:\${PATH}
eof
cp "${CMDER_ROOT}/vendor/user_profile.sh.default" "${CmderUserProfilePath}"
fi
# Source the users .bashrc file if it exists

7
vendor/cmder_exinit vendored
View File

@ -108,11 +108,6 @@ if [ ! "$CMDER_ROOT" = "" ] ; then
if [ ! -f "${CmderUserProfilePath}" ] ; then
echo Creating user startup file: "${CmderUserProfilePath}"
cat <<-eof >"${CmderUserProfilePath}"
# use this file to run your own startup commands for msys2 bash'
# To add a new vendor to the path, do something like:
# export PATH=\${CMDER_ROOT}/vendor/whatever:\${PATH}
eof
cp "${CMDER_ROOT}/vendor/user_profile.sh.default" "${CmderUserProfilePath}"
fi
fi

92
vendor/init.bat vendored
View File

@ -1,6 +1,6 @@
@echo off
set cmder_init_start=%time%
set CMDER_INIT_START=%time%
:: Init Script for cmd.exe
:: Created as part of cmder project
@ -14,6 +14,8 @@ set debug_output=0
set time_init=0
set fast_init=0
set max_depth=1
:: Add *nix tools to end of path. 0 turns off *nix tools.
set nix_tools=1
set "CMDER_USER_FLAGS= "
:: Find root dir
@ -79,6 +81,20 @@ call "%cmder_root%\vendor\lib\lib_profile"
%lib_console% show_error "The Git install root folder "%~2", you specified does not exist!"
exit /b
)
) else if /i "%1"=="/nix_tools" (
if "%2" equ "0" (
REM Do not add *nix tools to path
set nix_tools=0
shift
) else if "%2" equ "1" (
REM Add *nix tools to end of path
set nix_tools=1
shift
) else if "%2" equ "2" (
REM Add *nix tools to front of path
set nix_tools=2
shift
)
) else if /i "%1" == "/home" (
if exist "%~2" (
set "HOME=%~2"
@ -235,19 +251,37 @@ goto :CONFIGURE_GIT
:: Add git to the path
if defined GIT_INSTALL_ROOT (
rem add the unix commands at the end to not shadow windows commands like more
if exist "!GIT_INSTALL_ROOT!\cmd\git.exe" %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd" append
if exist "!GIT_INSTALL_ROOT!\mingw32" (
%lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw32\bin" append
) else if exist "!GIT_INSTALL_ROOT!\mingw64" (
%lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw64\bin" append
if %nix_tools% equ 1 (
%lib_console% debug_output init.bat "Preferring Windows commands"
set "path_position=append"
) else (
%lib_console% debug_output init.bat "Preferring *nix commands"
set "path_position="
)
if exist "!GIT_INSTALL_ROOT!\cmd\git.exe" %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd" !path_position!
if exist "!GIT_INSTALL_ROOT!\mingw32" (
%lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw32\bin" !path_position!
) else if exist "!GIT_INSTALL_ROOT!\mingw64" (
%lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw64\bin" !path_position!
)
if %nix_tools% geq 1 (
%lib_path% enhance_path "!GIT_INSTALL_ROOT!\usr\bin" !path_position!
)
%lib_path% enhance_path "!GIT_INSTALL_ROOT!\usr\bin" append
:: 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"
for /F "delims=" %%F in ('env /usr/bin/locale -uU 2') do (
set "LANG=%%F"
if not defined LANG (
:: Find locale.exe: From the git install root, from the path, using the git installed env, or fallback using the env from the path.
if not defined git_locale if exist "!GIT_INSTALL_ROOT!\usr\bin\locale.exe" set git_locale="!GIT_INSTALL_ROOT!\usr\bin\locale.exe"
if not defined git_locale for /F "delims=" %%F in ('where locale.exe 2^>nul') do (if not defined git_locale set git_locale="%%F")
if not defined git_locale if exist "!GIT_INSTALL_ROOT!\usr\bin\env.exe" set git_locale="!GIT_INSTALL_ROOT!\usr\bin\env.exe" /usr/bin/locale
if not defined git_locale set git_locale=env /usr/bin/locale
for /F "delims=" %%F in ('!git_locale! -uU 2') do (
set "LANG=%%F"
)
)
)
@ -279,7 +313,7 @@ if defined CMDER_USER_CONFIG (
:: 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',
:: must also be self executing, see '.\user_aliases.cmd.default',
:: and be in profile.d folder.
if not defined user_aliases (
if defined CMDER_USER_CONFIG (
@ -300,17 +334,17 @@ if "%CMDER_ALIASES%" == "1" (
setlocal enabledelayedexpansion
if not exist "%user_aliases%" (
echo Creating initial user_aliases store in "%user_aliases%"...
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.example" "%user_aliases%"
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%"
) else (
type "%user_aliases%" | findstr /i ";= Add aliases below here" >nul
type "%user_aliases%" | %WINDIR%\System32\findstr /i ";= Add aliases below here" >nul
if "!errorlevel!" == "1" (
echo Creating initial user_aliases store in "%user_aliases%"...
if defined CMDER_USER_CONFIG (
copy "%user_aliases%" "%user_aliases%.old_format"
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.example" "%user_aliases%"
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%"
) else (
copy "%user_aliases%" "%user_aliases%.old_format"
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.example" "%user_aliases%"
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%"
)
)
)
@ -348,6 +382,7 @@ if not defined HOME set "HOME=%USERPROFILE%"
set "initialConfig=%CMDER_ROOT%\config\user_profile.cmd"
if exist "%CMDER_ROOT%\config\user_profile.cmd" (
REM Create this file and place your own command in there
%lib_console% debug_output init.bat "Calling - %CMDER_ROOT%\config\user_profile.cmd"
call "%CMDER_ROOT%\config\user_profile.cmd"
)
@ -355,33 +390,14 @@ if defined CMDER_USER_CONFIG (
set "initialConfig=%CMDER_USER_CONFIG%\user_profile.cmd"
if exist "%CMDER_USER_CONFIG%\user_profile.cmd" (
REM Create this file and place your own command in there
%lib_console% debug_output init.bat "Calling - %CMDER_USER_CONFIG%\user_profile.cmd
call "%CMDER_USER_CONFIG%\user_profile.cmd"
)
)
if not exist "%initialConfig%" (
echo Creating user startup file: "%initialConfig%"
(
echo :: use this file to run your own startup commands
echo :: use in front of the command to prevent printing the command
echo.
echo :: uncomment this to have the ssh agent load when cmder starts
echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd"
echo.
echo :: uncomment the next two lines to use pageant as the ssh authentication agent
echo :: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock
echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-pageant.cmd"
echo.
echo :: you can add your plugins to the cmder path like so
echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%"
echo.
echo :: arguments in this batch are passed from init.bat, you can quickly parse them like so:
echo :: more useage can be seen by typing "cexec /?"
echo.
echo :: %%ccall%% "/customOption" "command/program"
echo.
echo @echo off
) >"%initialConfig%"
copy "%CMDER_ROOT%\vendor\user_profile.cmd.default" "%initialConfig%"
)
if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMDER_ROOT%\vendor\bin\alias.cmd" (
@ -400,9 +416,9 @@ if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMD
set initialConfig=
set CMDER_CONFIGURED=1
set cmder_init_end=%time%
set CMDER_INIT_END=%time%
if %time_init% gtr 0 (
"%cmder_root%\vendor\bin\timer.cmd" %cmder_init_start% %cmder_init_end%
"%cmder_root%\vendor\bin\timer.cmd" %CMDER_INIT_START% %CMDER_INIT_END%
)
exit /b

View File

@ -27,7 +27,7 @@ exit /b
::: file <in> full path to file containing lib_routines to display
:::.
:::-------------------------------------------------------------------------------
for /f "tokens=* delims=:" %%a in ('type "%~1" ^| findstr /i /r "^:::"') do (
for /f "tokens=* delims=:" %%a in ('type "%~1" ^| %WINDIR%\System32\findstr /i /r "^:::"') do (
rem echo a="%%a"
if "%%a"=="." (
@ -61,9 +61,9 @@ exit /b
::: file <in> full path to file containing lib_routines to display
:::.
:::-------------------------------------------------------------------------------
echo %comspec% | find /i "\cmd.exe" > nul && set "CMDER_SHELL=cmd"
echo %comspec% | find /i "\tcc.exe" > nul && set "CMDER_SHELL=tcc"
echo %comspec% | find /i "\tccle" > nul && set "CMDER_SHELL=tccle"
echo %comspec% | %WINDIR%\System32\find /i "\cmd.exe" > nul && set "CMDER_SHELL=cmd"
echo %comspec% | %WINDIR%\System32\find /i "\tcc.exe" > nul && set "CMDER_SHELL=tcc"
echo %comspec% | %WINDIR%\System32\find /i "\tccle" > nul && set "CMDER_SHELL=tccle"
if not defined CMDER_CLINK (
set CMDER_CLINK=1

View File

@ -68,14 +68,14 @@ exit /b
if "%CMDER_CONFIGURED%" == "1" (
%lib_console% debug_output :enhance_path "Env Var - find_query=%find_query%"
echo "%path%"|findstr >nul /I /R ";%find_query%\"$"
echo "%path%"|%WINDIR%\System32\findstr >nul /I /R ";%find_query%\"$"
if "!ERRORLEVEL!" == "0" set found=1
)
%lib_console% debug_output :enhance_path "Env Var 1 - found=!found!"
if "!found!" == "0" (
if "%CMDER_CONFIGURED%" == "1" (
echo "%path%"|findstr >nul /i /r ";%find_query%;"
echo "%path%"|%WINDIR%\System32\findstr >nul /i /r ";%find_query%;"
if "!ERRORLEVEL!" == "0" set found=1
)
%lib_console% debug_output :enhance_path "Env Var 2 - found=!found!"

22
vendor/lib/start-ssh-agent.sh vendored Normal file
View File

@ -0,0 +1,22 @@
# Copied from https://help.github.com/articles/working-with-ssh-key-passphrases
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add
fi
unset env

55
vendor/profile.ps1 vendored
View File

@ -128,20 +128,30 @@ if (-not (test-path "$ENV:CMDER_ROOT\config\profile.d")) {
}
pushd $ENV:CMDER_ROOT\config\profile.d
foreach ($x in Get-ChildItem *.ps1) {
foreach ($x in Get-ChildItem *.psm1) {
# write-host write-host Sourcing $x
Import-Module $x
}
foreach ($x in Get-ChildItem *.ps1) {
# write-host write-host Sourcing $x
. $x
}
popd
# Drop *.ps1 files into "$ENV:CMDER_USER_CONFIG\config\profile.d"
# to source them at startup. Requires using cmder.exe /C [cmder_user_root_path] argument
if ($ENV:CMDER_USER_CONFIG -ne "" -and (test-path "$ENV:CMDER_USER_CONFIG\profile.d")) {
pushd $ENV:CMDER_USER_CONFIG\profile.d
foreach ($x in Get-ChildItem *.ps1) {
foreach ($x in Get-ChildItem *.psm1) {
# write-host write-host Sourcing $x
Import-Module $x
}
foreach ($x in Get-ChildItem *.ps1) {
# write-host write-host Sourcing $x
. $x
}
popd
}
@ -153,7 +163,7 @@ if (test-path "$env:CMDER_ROOT\config\user-profile.ps1") {
$CmderUserProfilePath = Join-Path $env:CMDER_ROOT "config\user_profile.ps1"
if (Test-Path $CmderUserProfilePath) {
# Create this file and place your own command in there.
Import-Module "$CmderUserProfilePath"
. "$CmderUserProfilePath" # user_profile.ps1 is not a module DO NOT USE import-module
}
if ($ENV:CMDER_USER_CONFIG) {
@ -166,46 +176,13 @@ if ($ENV:CMDER_USER_CONFIG) {
$CmderUserProfilePath = Join-Path $ENV:CMDER_USER_CONFIG "user_profile.ps1"
if (Test-Path $CmderUserProfilePath) {
Import-Module "$CmderUserProfilePath"
. "$CmderUserProfilePath" # user_profile.ps1 is not a module DO NOT USE import-module
}
}
if (! (Test-Path $CmderUserProfilePath) ) {
# This multiline string cannot be indented, for this reason I've not indented the whole block
Write-Host -BackgroundColor Darkgreen -ForegroundColor White "First Run: Creating user startup file: $CmderUserProfilePath"
$UserProfileTemplate = @'
# Use this file to run your own startup commands
## Prompt Customization
<#
.SYNTAX
<PrePrompt><CMDER DEFAULT>
λ <PostPrompt> <repl input>
.EXAMPLE
<PrePrompt>N:\Documents\src\cmder [master]
λ <PostPrompt> |
#>
[ScriptBlock]$PrePrompt = {
}
# Replace the cmder prompt entirely with this.
# [ScriptBlock]$CmderPrompt = {}
[ScriptBlock]$PostPrompt = {
}
## <Continue to add your own>
'@
New-Item -ItemType File -Path $CmderUserProfilePath -Value $UserProfileTemplate > $null
Write-Host -BackgroundColor Darkgreen -ForegroundColor White "First Run: Creating user startup file: $CmderUserProfilePath"
Copy-Item "$env:CMDER_ROOT\vendor\user_profile.ps1.default" -Destination $CmderUserProfilePath
}
# Once Created these code blocks cannot be overwritten

19
vendor/user_profile.cmd.default vendored Normal file
View File

@ -0,0 +1,19 @@
:: use this file to run your own startup commands
:: use in front of the command to prevent printing the command
:: uncomment this to have the ssh agent load when cmder starts
:: call "%GIT_INSTALL_ROOT%/cmd/start-ssh-agent.cmd" /k exit
:: uncomment the next two lines to use pageant as the ssh authentication agent
:: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock
:: call "%GIT_INSTALL_ROOT%/cmd/start-ssh-pageant.cmd"
:: you can add your plugins to the cmder path like so
:: set "PATH=%CMDER_ROOT%\vendor\whatever;%PATH%"
:: arguments in this batch are passed from init.bat, you can quickly parse them like so:
:: more useage can be seen by typing "cexec /?"
:: %ccall% "/customOption" "command/program"
@echo off

25
vendor/user_profile.ps1.default vendored Normal file
View File

@ -0,0 +1,25 @@
# Use this file to run your own startup commands
## Prompt Customization
<#
.SYNTAX
<PrePrompt><CMDER DEFAULT>
λ <PostPrompt> <repl input>
.EXAMPLE
<PrePrompt>N:\Documents\src\cmder [master]
λ <PostPrompt> |
#>
[ScriptBlock]$PrePrompt = {
}
# Replace the cmder prompt entirely with this.
# [ScriptBlock]$CmderPrompt = {}
[ScriptBlock]$PostPrompt = {
}
## <Continue to add your own>

7
vendor/user_profile.sh.default vendored Normal file
View File

@ -0,0 +1,7 @@
# 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}
# Uncomment this to have the ssh agent load with the first bash terminal
# . "${CMDER_ROOT}/vendor/lib/start-ssh-agent.sh"