[关闭]
@tsingwong 2016-09-08T06:22:18.000000Z 字数 1275 阅读 1106

Cmder 使用问题解决办法

Cmder


完美解决一切中文乱码情况

Cmder 中的乱码包括中文乱码和路径中文乱码。

修改 Cmder 安装目录下的 vendor/clink.lua文件
将 20 行的 set_prompt_filter 这个函数替换为下面

  1. function set_prompt_filter()
  2. -- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
  3. -- pure ASCII will get garbled. So try to parse the current directory from the original prompt
  4. -- and only if that doesn't work, use get_cwd() directly.
  5. -- The matching relies on the default prompt which ends in X:\PATH\PATH>
  6. -- (no network path possible here!)
  7. local old_prompt = clink.prompt.value
  8. local cwd = old_prompt:match('.*(.:[^>]*)>')
  9. if cwd == nil then cwd = clink.get_cwd() end
  10. -- environment systems like pythons virtualenv change the PROMPT and usually
  11. -- set some variable. But the variables are differently named and we would never
  12. -- get them all, so try to parse the env name out of the PROMPT.
  13. -- envs are usually put in round or square parentheses and before the old prompt
  14. local env = old_prompt:match('.*%(([^%)]+)%).+:')
  15. -- also check for square brackets
  16. if env == nil then env = old_prompt:match('.*%[([^%]]+)%].+:') end
  17. -- build our own prompt
  18. -- orig: $E[1;32;40m$P$S{git}{hg}$S$_$E[1;30;40m{lamb}$S$E[0m
  19. -- color codes: "\x1b[1;37;40m"
  20. local cmder_prompt = "\x1b[1;32;40m{cwd} {git}{hg} \n\x1b[1;30;40m{lamb} \x1b[0m"
  21. cmder_prompt = string.gsub(cmder_prompt, "{cwd}", cwd)
  22. if env == nil then
  23. lambda = "λ"
  24. else
  25. lambda = "("..env..") λ"
  26. end
  27. clink.prompt.value = string.gsub(cmder_prompt, "{lamb}", lambda)
  28. end
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注