@@ -18,12 +18,34 @@ dofile(clink_lua_file)
18
18
-- which echo) don't get the ugly '{lamb}' shown.
19
19
---
20
20
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
21
39
-- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m
22
40
-- 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 )
27
49
end
28
50
29
51
---
0 commit comments