From a542f4e20cffd12d6af34979530d947fa372c033 Mon Sep 17 00:00:00 2001 From: Jan Schulz Date: Tue, 24 May 2016 14:26:14 +0200 Subject: [PATCH] cmd: change the prompt in lua This keeps the PROMPT variable as is and changes the prompt to the cmder style in the clink code. This has two advantages: * opening a cmd in a cmder session will now show the old prompt code instead of a ugly raw prompt without the replacements. This led to ugly output when a batch file echoed their content (e.g `conda build recipe/`). * when a command rewrites the prompt (e.g. an activate in a virtualenv), these command sometimes simply overwrites the PROMPT so that the cmder enhancements were not anymore in place. Now we simply don't care and overwrite it with our stuff in the clink part. This might mean that a user has to install a lua script so that e.g. conda environments are visible on the prompt. --- vendor/clink.lua | 17 +++++++++++++++++ vendor/init.bat | 4 ---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/vendor/clink.lua b/vendor/clink.lua index 133392b..2867d17 100644 --- a/vendor/clink.lua +++ b/vendor/clink.lua @@ -12,6 +12,21 @@ dofile(clink_lua_file) -- now add our own things... +--- + -- 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 = new_value +end + + function lambda_prompt_filter() clink.prompt.value = string.gsub(clink.prompt.value, "{lamb}", "λ") end @@ -230,6 +245,8 @@ function git_prompt_filter() return false end +-- 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(lambda_prompt_filter, 40) 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 c4df0db..730efea 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -17,10 +17,6 @@ if not defined CMDER_ROOT ( :: 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 - :: Pick right version of clink if "%PROCESSOR_ARCHITECTURE%"=="x86" ( set architecture=86