mirror of
				https://github.com/cmderdev/cmder.git
				synced 2025-10-31 09:22:15 +08:00 
			
		
		
		
	Merge pull request #1070 from janschulz/unicode_path_prompt
Parse the original prompt for cwd and env names
This commit is contained in:
		
							
								
								
									
										30
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										30
									
								
								vendor/clink.lua
									
									
									
									
										vendored
									
									
								
							| @@ -18,12 +18,34 @@ dofile(clink_lua_file) | |||||||
|  -- which echo) don't get the ugly '{lamb}' shown. |  -- which echo) don't get the ugly '{lamb}' shown. | ||||||
| --- | --- | ||||||
| function set_prompt_filter() | function set_prompt_filter() | ||||||
|  |     -- get_cwd() is differently encoded than the clink.prompt.value, so everything other than | ||||||
|  |     -- pure ASCII will get garbled. So try to parse the current directory from the original prompt | ||||||
|  |     -- and only if that doesn't work, use get_cwd() directly. | ||||||
|  |     -- The matching relies on the default prompt which ends in X:\PATH\PATH> | ||||||
|  |     -- (no network path possible here!) | ||||||
|  |     local old_prompt = clink.prompt.value | ||||||
|  |     local cwd = old_prompt:match('.*(.:[^>]*)>') | ||||||
|  |     if cwd == nil then cwd = clink.get_cwd() end | ||||||
|  |      | ||||||
|  |     -- environment systems like pythons virtualenv change the PROMPT and usually | ||||||
|  |     -- set some variable. But the variables are differently named and we would never | ||||||
|  |     -- get them all, so try to parse the env name out of the PROMPT. | ||||||
|  |     -- envs are usually put in round or square parentheses and before the old prompt | ||||||
|  |     local env = old_prompt:match('.*%(([^%)]+)%).+:') | ||||||
|  |     -- also check for square brackets | ||||||
|  |     if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end | ||||||
|  |      | ||||||
|  |     -- build our own prompt | ||||||
|     -- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m |     -- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m | ||||||
|     -- color codes: "\x1b[1;37;40m" |     -- color codes: "\x1b[1;37;40m" | ||||||
|     cwd = clink.get_cwd() |     local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m" | ||||||
|     prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m" |     cmder_prompt = string.gsub(cmder_prompt, "{cwd}", cwd) | ||||||
|     new_value = string.gsub(prompt, "{cwd}", cwd) |     if env == nil then | ||||||
|     clink.prompt.value = string.gsub(new_value, "{lamb}", "λ") |         lambda = "λ" | ||||||
|  |     else | ||||||
|  |         lambda = "("..env..") λ" | ||||||
|  |     end | ||||||
|  |     clink.prompt.value = string.gsub(cmder_prompt, "{lamb}", lambda) | ||||||
| end | end | ||||||
|  |  | ||||||
| --- | --- | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user