mirror of
https://github.com/cmderdev/cmder.git
synced 2024-11-10 09:49:12 +08:00
Allow scripts to disable part of the Cmder prompt.
The Cmder prompt normally includes version control info, which involves running some potentially expensive commands. The cmder-powerline-prompt project (and maybe other projects) replaces the Cmder prompt and runs the same potentially expensive commands -- so expensive commands get run twice! This change makes it possible for the user and/or other scripts to disable the version control part of the built-in Cmder prompt. https://github.com/chrisant996/cmder-powerline-prompt
This commit is contained in:
parent
91aabe75af
commit
f6c2657b23
34
vendor/clink.lua
vendored
34
vendor/clink.lua
vendored
@ -85,6 +85,13 @@ else
|
||||
end
|
||||
|
||||
|
||||
---
|
||||
-- Global variable so other Lua scripts can detect whether they're in a Cmder
|
||||
-- shell session.
|
||||
---
|
||||
CMDER_SESSION = true
|
||||
|
||||
|
||||
---
|
||||
-- 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
|
||||
@ -135,6 +142,10 @@ local function set_prompt_filter()
|
||||
prompt_singleLine = false
|
||||
end
|
||||
|
||||
if prompt_includeVersionControl == nil then
|
||||
prompt_includeVersionControl = true
|
||||
end
|
||||
|
||||
if prompt_type == 'folder' then
|
||||
cwd = get_folder_name(cwd)
|
||||
end
|
||||
@ -155,7 +166,12 @@ local function set_prompt_filter()
|
||||
|
||||
if env ~= nil then env = "("..env..") " else env = "" end
|
||||
|
||||
prompt = get_uah_color() .. "{uah}" .. get_cwd_color() .. "{cwd}{git}{hg}{svn}" .. get_lamb_color() .. cr .. "{lamb} \x1b[0m"
|
||||
if uah ~= '' then uah = get_uah_color() .. uah end
|
||||
if cwd ~= '' then cwd = get_cwd_color() .. cwd end
|
||||
|
||||
local version_control = prompt_includeVersionControl and "{git}{hg}{svn}" or ""
|
||||
|
||||
prompt = "{uah}{cwd}" .. version_control .. get_lamb_color() .. cr .. "{lamb} \x1b[0m"
|
||||
prompt = string.gsub(prompt, "{uah}", uah)
|
||||
prompt = string.gsub(prompt, "{cwd}", cwd)
|
||||
prompt = string.gsub(prompt, "{env}", env)
|
||||
@ -430,6 +446,11 @@ end
|
||||
|
||||
local function git_prompt_filter()
|
||||
|
||||
-- Don't do any git processing if the prompt doesn't want to show git info.
|
||||
if not clink.prompt.value:find("{git}") then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Colors for git status
|
||||
local colors = {
|
||||
clean = get_clean_color(),
|
||||
@ -484,6 +505,11 @@ end
|
||||
|
||||
local function hg_prompt_filter()
|
||||
|
||||
-- Don't do any hg processing if the prompt doesn't want to show hg info.
|
||||
if not clink.prompt.value:find("{hg}") then
|
||||
return false
|
||||
end
|
||||
|
||||
local result = ""
|
||||
|
||||
local hg_dir = get_hg_dir()
|
||||
@ -523,6 +549,12 @@ local function hg_prompt_filter()
|
||||
end
|
||||
|
||||
local function svn_prompt_filter()
|
||||
|
||||
-- Don't do any svn processing if the prompt doesn't want to show svn info.
|
||||
if not clink.prompt.value:find("{svn}") then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Colors for svn status
|
||||
local colors = {
|
||||
clean = get_clean_color(),
|
||||
|
4
vendor/cmder_prompt_config.lua.default
vendored
4
vendor/cmder_prompt_config.lua.default
vendored
@ -34,6 +34,10 @@ prompt_singleLine = false
|
||||
-- NOTE: This only takes effect if using Clink v1.2.10 or higher.
|
||||
prompt_overrideGitStatusOptIn = false
|
||||
|
||||
-- OPTIONAL. If true then Cmder includes git, mercurial, and subversion status in the prompt.
|
||||
-- default is true
|
||||
prompt_includeVersionControl = true
|
||||
|
||||
-- Prompt Attributes
|
||||
--
|
||||
-- Colors
|
||||
|
Loading…
Reference in New Issue
Block a user