mirror of
https://github.com/cmderdev/cmder.git
synced 2025-06-15 06:07:50 +08:00
Merge branch 'development' into cmder_exinit
This commit is contained in:
243
vendor/clink.lua
vendored
Normal file
243
vendor/clink.lua
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
-- 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
|
||||
|
||||
---
|
||||
-- Resolves closest directory location for specified directory.
|
||||
-- Navigates subsequently up one level and tries to find specified directory
|
||||
-- @param {string} path Path to directory will be checked. If not provided
|
||||
-- current directory will be used
|
||||
-- @param {string} dirname Directory name to search for
|
||||
-- @return {string} Path to specified directory or nil if such dir not found
|
||||
local function get_dir_contains(path, dirname)
|
||||
|
||||
-- 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
|
||||
|
||||
-- Navigates up one level
|
||||
local function up_one_level(path)
|
||||
if path == nil then path = '.' end
|
||||
if path == '.' then path = clink.get_cwd() end
|
||||
return pathname(path)
|
||||
end
|
||||
|
||||
-- Checks if provided directory contains git directory
|
||||
local function has_specified_dir(path, specified_dir)
|
||||
if path == nil then path = '.' end
|
||||
local found_dirs = clink.find_dirs(path..'/'..specified_dir)
|
||||
if #found_dirs > 0 then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
-- Set default path to current directory
|
||||
if path == nil then path = '.' end
|
||||
|
||||
-- If we're already have .git directory here, then return current path
|
||||
if has_specified_dir(path, dirname) then
|
||||
return path..'/'..dirname
|
||||
else
|
||||
-- Otherwise go up one level and make a recursive call
|
||||
local parent_path = up_one_level(path)
|
||||
if parent_path == path then
|
||||
return nil
|
||||
else
|
||||
return get_dir_contains(parent_path, dirname)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
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 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
|
||||
|
||||
---
|
||||
-- Find out current branch
|
||||
-- @return {false|mercurial branch name}
|
||||
---
|
||||
function get_hg_branch()
|
||||
for line in io.popen("hg branch 2>nul"):lines() do
|
||||
local m = line:match("(.+)$")
|
||||
if m then
|
||||
return m
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---
|
||||
-- Get the status of working dir
|
||||
-- @return {bool}
|
||||
---
|
||||
function get_hg_status()
|
||||
for line in io.popen("hg status"):lines() do
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function hg_prompt_filter()
|
||||
|
||||
-- Colors for mercurial status
|
||||
local colors = {
|
||||
clean = "\x1b[1;37;40m",
|
||||
dirty = "\x1b[31;1m",
|
||||
}
|
||||
|
||||
if get_hg_dir() then
|
||||
-- if we're inside of mercurial repo then try to detect current branch
|
||||
local branch = get_hg_branch()
|
||||
if branch then
|
||||
-- Has branch => therefore it is a mercurial folder, now figure out status
|
||||
if get_hg_status() then
|
||||
color = colors.clean
|
||||
else
|
||||
color = colors.dirty
|
||||
end
|
||||
|
||||
clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", color.."("..branch..")")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- No mercurial present or not in mercurial file
|
||||
clink.prompt.value = string.gsub(clink.prompt.value, "{hg}", "")
|
||||
return false
|
||||
end
|
||||
|
||||
---
|
||||
-- Find out current branch
|
||||
-- @return {nil|git branch name}
|
||||
---
|
||||
function get_git_branch(git_dir)
|
||||
local git_dir = git_dir or get_git_dir()
|
||||
|
||||
-- If git directory not found then we're probably outside of repo
|
||||
-- or something went wrong. The same is when head_file is nil
|
||||
local head_file = git_dir and io.open(git_dir..'/HEAD')
|
||||
if not head_file then return end
|
||||
|
||||
local HEAD = head_file:read()
|
||||
head_file:close()
|
||||
|
||||
-- if HEAD matches branch expression, then we're on named branch
|
||||
-- otherwise it is a detached commit
|
||||
local branch_name = HEAD:match('ref: refs/heads/(.+)')
|
||||
return branch_name or 'HEAD detached at '..HEAD:sub(1, 7)
|
||||
end
|
||||
|
||||
---
|
||||
-- Get the status of working dir
|
||||
-- @return {bool}
|
||||
---
|
||||
function get_git_status()
|
||||
return io.popen("git diff --quiet --ignore-submodules HEAD 2>nul")
|
||||
end
|
||||
|
||||
function git_prompt_filter()
|
||||
|
||||
-- Colors for git status
|
||||
local colors = {
|
||||
clean = "\x1b[1;37;40m",
|
||||
dirty = "\x1b[31;1m",
|
||||
}
|
||||
|
||||
local git_dir = get_git_dir()
|
||||
if git_dir then
|
||||
-- if we're inside of git repo then try to detect current branch
|
||||
local branch = get_git_branch(git_dir)
|
||||
if branch then
|
||||
-- Has branch => therefore it is a git folder, now figure out status
|
||||
if get_git_status() then
|
||||
color = colors.clean
|
||||
else
|
||||
color = colors.dirty
|
||||
end
|
||||
|
||||
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", color.."("..branch..")")
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- No git present or not in git file
|
||||
clink.prompt.value = string.gsub(clink.prompt.value, "{git}", "")
|
||||
return false
|
||||
end
|
||||
|
||||
clink.prompt.register_filter(lambda_prompt_filter, 40)
|
||||
clink.prompt.register_filter(hg_prompt_filter, 50)
|
||||
clink.prompt.register_filter(git_prompt_filter, 50)
|
||||
|
||||
local completions_dir = clink.get_env('CMDER_ROOT')..'/vendor/clink-completions/'
|
||||
for _,lua_module in ipairs(clink.find_files(completions_dir..'*.lua')) do
|
||||
-- Skip files that starts with _. This could be useful if some files should be ignored
|
||||
if not string.match(lua_module, '^_.*') then
|
||||
local filename = completions_dir..lua_module
|
||||
-- use dofile instead of require because require caches loaded modules
|
||||
-- so config reloading using Alt-Q won't reload updated modules.
|
||||
dofile(filename)
|
||||
end
|
||||
end
|
||||
|
18
vendor/init.bat
vendored
18
vendor/init.bat
vendored
@ -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,14 +57,14 @@
|
||||
)
|
||||
|
||||
:: 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"
|
||||
@ -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" (
|
||||
|
31
vendor/profile.ps1
vendored
31
vendor/profile.ps1
vendored
@ -32,7 +32,7 @@ try {
|
||||
# $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
|
||||
}
|
||||
@ -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 += '\'
|
||||
}
|
||||
|
||||
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}"
|
||||
# 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"
|
||||
if(Test-Path $CmderUserProfilePath) {
|
||||
# Create this file and place your own command in there.
|
||||
|
16
vendor/sources.json
vendored
16
vendor/sources.json
vendored
@ -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"
|
||||
}
|
||||
]
|
||||
|
Reference in New Issue
Block a user