Cygwin是一款优秀的windows下模拟Linux环境的软件!
在默认情况下,cygwin的大部分命令是不支持中文的,比如ls,显示出来的都是问号
但是我们可以通过修改一些设置使它支持中文
首先,进入到用户主目录下
$cd ~
然后找到.inputrc,没有的话就新建
例如:
1.在cygwin/home/[user]/.bash_profile的末尾添加如下代码
alias ls='ls --color --show-control-chars'
export LC_ALL=zh_CN.GB23122
export LC_CTYPE=zh_CN.GB2312
export LANG=zh_CN.GB2312
export XMODIFIERS="@im=Chinput"3
stty cs8 -istrip
stty pass8
export LESSCHARSET=latin1
2.修改cygwin/home/[user]/.inputrc中的代码,去掉相关注释即可
set meta-flag on
set convert-meta off
set output-meta on
set input-meta on
3.在cygwin/home/[user]/.bashrc末尾添加
上述步骤解决了cygwin下中文显示乱码与中文输入的问题.
网上找了很多解决方法, 把环境设为zh_CN.GB23122, 但是我试了还是不行,然后自己设置en_US.UTF-8, nano编辑文本的时候可以, 但是保存文件名称为中文却不行, 最后en_US.UTF-16就OK了, 但是还是有个问题不明白, export LESSCHARSET=latin1 这个不知道是什么意思, 谁能告诉我。
如果你改变了home的路径, 请参考以下方法解决:
如果HOME目录改变则需要编辑cygwin.bat
在bash命令之前加入set HOME=C:\cygwin\home
$ more cygwin.bat
@echo off
C:
chdir C:\cygwin\bin
set HOME=C:\cygwin\home
bash --login -i
aaronvox#aaronvox ~
$ pwd
/home
这样操作之后的配置文件可能为:
aaronvox#aaronvox ~
$ ls -a
. .. .bash_profile .bashrc .inputc .inputrc
aaronvox#aaronvox ~
$ more .inputc
set meta-flag on
set convert-meta o
set output-meta on
set input-meta on
aaronvox#aaronvox ~
$ more .bash_profile
# base-files version 3.4-2
# WARNING
#
# IF THIS .bash_profile IS MODIFIED IT WILL NOT BE UPDATED BY THE CYGWIN
# SETUP PROGRAM. IT BECOMES YOUR RESPONSIBILITY.
#
# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.bash_profile
# ~/.bash_profile: executed by bash for login shells.
# source the system wide bashrc if it exists
if [ -e /etc/bash.bashrc ] ; then
source /etc/bash.bashrc
fi
# source the users bashrc if it exists
if [ -e "${HOME}/.bashrc" ] ; then
source "${HOME}/.bashrc"
fi
# Set PATH so it includes user's private bin if it exists
# if [ -d "${HOME}/bin" ] ; then
# PATH=${HOME}/bin:${PATH}
# fi
# Set MANPATH so it includes users' private man if it exists
# if [ -d "${HOME}/man" ]; then
# MANPATH=${HOME}/man:${MANPATH}
# fi
# Set INFOPATH so it includes users' private info if it exists
# if [ -d "${HOME}/info" ]; then
# INFOPATH=${HOME}/info:${INFOPATH}
# fi
简单的做了以上修改后,就可以支持中文了!
文章评论