Skip to content

Commit 832c199

Browse files
authored
Merge pull request #1070 from janschulz/unicode_path_prompt
Parse the original prompt for cwd and env names
2 parents 19672aa + 6b10771 commit 832c199

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

vendor/clink.lua

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,34 @@ dofile(clink_lua_file)
1818
-- which echo) don't get the ugly '{lamb}' shown.
1919
---
2020
function set_prompt_filter()
21+
-- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
22+
-- pure ASCII will get garbled. So try to parse the current directory from the original prompt
23+
-- and only if that doesn't work, use get_cwd() directly.
24+
-- The matching relies on the default prompt which ends in X:\PATH\PATH>
25+
-- (no network path possible here!)
26+
local old_prompt = clink.prompt.value
27+
local cwd = old_prompt:match('.*(.:[^>]*)>')
28+
if cwd == nil then cwd = clink.get_cwd() end
29+
30+
-- environment systems like pythons virtualenv change the PROMPT and usually
31+
-- set some variable. But the variables are differently named and we would never
32+
-- get them all, so try to parse the env name out of the PROMPT.
33+
-- envs are usually put in round or square parentheses and before the old prompt
34+
local env = old_prompt:match('.*%(([^%)]+)%).+:')
35+
-- also check for square brackets
36+
if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end
37+
38+
-- build our own prompt
2139
-- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m
2240
-- color codes: "\x1b[1;37;40m"
23-
cwd = clink.get_cwd()
24-
prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m"
25-
new_value = string.gsub(prompt, "{cwd}", cwd)
26-
clink.prompt.value = string.gsub(new_value, "{lamb}", "λ")
41+
local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m"
42+
cmder_prompt = string.gsub(cmder_prompt, "{cwd}", cwd)
43+
if env == nil then
44+
lambda = "λ"
45+
else
46+
lambda = "("..env..") λ"
47+
end
48+
clink.prompt.value = string.gsub(cmder_prompt, "{lamb}", lambda)
2749
end
2850

2951
---

0 commit comments

Comments
 (0)