Home  >  Q&A  >  body text

ruby - windows 7下git bash终端如何向cmd终端一样支持utf-8字符?

本人打算在windows 7下,使用octopress搭建博客。

有一个问题不得其解:
cmd终端,使用chcp 65001, rake generate编译没有问题。

但是,用git bash终端,已经设置了变量如下:
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LESSCHARSET=utf-8

rake generate产生下面问题:

octopress/plugins/backtick_code_block.rb:13:in gsub': incompat ible character encodings: UTF-8 and GBK (Encoding::CompatibilityError) from octopress/plugins/backtick_code_block.rb:13:inre nder_code_block'
from octopress/plugins/octopress_filters.rb:12:in pre_ filter' from octopress/plugins/octopress_filters.rb:28:inpre_ render'
from octopress/plugins/post_filters.rb:112:in block in pre_render' from octopress/plugins/post_filters.rb:111:ineach'
from octopress/plugins/post_filters.rb:111:in pre_rend er' from octopress/plugins/post_filters.rb:166:indo_layou t'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/jekyll-0.12.0/lib/jekyll/po
st.rb:195:in render' from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/jekyll-0.12.0/lib/jekyll/si te.rb:200:inblock in render'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/jekyll-0.12.0/lib/jekyll/si
te.rb:199:in each' from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/jekyll-0.12.0/lib/jekyll/si te.rb:199:inrender'
from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/jekyll-0.12.0/lib/jekyll/si
te.rb:41:in process' from c:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/jekyll-0.12.0/bin/jekyll:26 4:in'
from c:/Ruby200-x64/bin/jekyll:23:in load' from c:/Ruby200-x64/bin/jekyll:23:in

'

有谁可以帮忙分析一下,是怎么回事,git bash有等价cmd终端的chcp类似命令吗?

补充说明:
在当前git bash终端下,输入中文是没有问题的;同时中文问题只是发生在代码高亮模块里,其他位置的中文是没有这个情况的,如果不需要代码高亮,也是没有这个问题。

高洛峰高洛峰2734 days ago692

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-24 09:14:15

    Since the git bash terminal is basically equivalent to the cmd terminal.

    Refer to this article http://www.soimort.org/posts/118/ for detailed instructions on Windows terminal.

    Since I want to operate on git bash, git bash provides most of the commands used by Linux.

    Written a script,

    #! /bin/sh
    
    /c/Windows/System32/chcp.com 65001
    
    rake generate
    
    /c/Windows/System32/chcp.com 936
    

    Temporarily changed to 65001 mode when compiling, and restored to the current 936 mode after compilation.

    @evian, Thank you very much for your enthusiastic, timely and professional support! ! !

    reply
    0
  • Cancelreply