cygwin設定中文

2021-09-01 03:28:36 字數 4099 閱讀 4805

cygwin\home\username\.bashrc

# 讓ls和dir命令顯示中文和顏色

alias ls='ls --show-control-chars --color'

alias dir='dir -n --color'

# 設定為中文環境,使提示成為中文

export lang="zh_cn.gbk"

# 輸出為中文編碼

export output_charset="gbk"

cygwin\home\username\.inputrc

# 可以輸入中文

set meta-flag on

set output-meta on

set convert-meta off

# 忽略大小寫

set completion-ignore-case on

, cygwin.bat:

@echo off

set make_mode=unix

set path=d:\cygwin\bin;%path%

set home=d:\home

bash

2, 在~目錄下的.bashrc檔案中加入:

# 讓ls和dir命令顯示中文和顏色

alias dir='dir -n --color'

alias less='/bin/less -r'

alias ls='/bin/ls -f --color=tty --show-control-chars'

# 設定為中文環境,使提示成為中文

export lang="zh_cn.gb2312"

# 輸出為中文編碼

export output_charset="gb2312"

3,bash將到d:\home目錄下尋找初始化檔案。

預設情況下,bash命令列不能輸入漢字,必須在~目錄下建立檔案.inputrc,內容如下:

# 忽略大小寫

set completion-ignore-case on

# 可以輸入中文

set convert-meta off

set input-meta on

set output-meta on

跟emacs存在同樣的問題,就是顯示不了uft8編碼下的漢字

cygwin工具是gnu工具在win32平台上的移植版本,它盡可能地遵循posix標準。其中包括c/c++編譯器gcc,textutils,fileutils,bash等等。本文將闡述如何在cygwin(b20)中使用中文。

cygwin通過cygnus.bat(位於x:\cygnus\cygwin-b20)啟動bash,內容如下:

@echo offset make_mode=unixset path=c:\cygnus\cygwin~1\h-i586~1\bin;%path%bash

在其中加入(bash之前)一句:

set home=x:\homename

x:為碟符,\homename為已存在的目錄名,例如c:\myhome。bash將到x:\homename目錄下尋找初始化檔案。

預設情況下,bash命令列不能輸入漢字,必須在x:\homename目錄下建立檔案.inputrc,內容如下:

set meta-flag onset convert-meta offset output-meta on

這幾行主要是實現命令列上實現漢字的輸入以及顯示。 比如想輸入漢字的檔名等等。

注意:在cygwin-b20中.inputrc必須為un*x檔案格式。

bash在windows 9x中不能接受來自dos視窗的漢字輸入。

為了讓less命令顯示漢字在x:\homename\.bashrc中加入:

export lesscharset=latin1

為了讓ls命令顯示漢字檔案和目錄名在x:\homename\.bashrc中加入:

alias ls='ls -n --color'#***********************************=.bashrc 2009-10-09

cygwin 1.70******************************====# shell options# #############alias

ls='ls -hf --color=tty' # classify files in colouralias dir='ls

--color=auto --format=vertical'alias vdir='ls --color=auto --format=long'alias

ll='ls -l' # long listalias la='ls -a'

# all but . and ..alias l='ls -cf' ## some

example functions# function settitle() ###################### 以下為新增部分 #################################

cygwin中取\usr\share\locale\zh_cn\lc_messages中*.mo檔案,如果提示資訊中#

的字符集為utf8則會顯示有誤(不知何解?,magiclinux無類似情況),為gb2312#

則正常,大概與gettext這個模組有關,這個模組的作用是使linux程式提示資訊#

區域話,即不同地區用不同語言,即常說的i18n;像我們設定的zh_cn.gbk,「.」#

之前部分「zh_cn」表示地區即「中國大陸」,後面部分「gbk」表示字符集編碼,#

像我們下面的設定,當程式呼叫時會到\usr\share\locale\目錄中查詢,發現地#

區為「zh_cn」則到該目錄中查詢程式對應的*.mo檔案,*.mo檔案的名稱是在呼叫#

的程式中設定了的。然後取該語種的對應提示,然後按編碼(在mo檔案中指明了)#

處理該文字。#

當然這些不是自動處理的,要在程式中呼叫像setlocale、textdomian、gettext#

這樣的函式處理。#

在cygwin中有些程式,做了下面的設定,因為對應的mo檔案中編碼為utf8而無法#

顯示,我是直接將它刪除,之後程式會因為找不到mo檔案而用預設的英文來顯示#

的。(下面的編碼設定並沒有錯,應該是cygwin程式中的bug,只是設定了lc_all#

就沒必要設lang了,有的文件上面這樣寫的:))export set lc_all=zh_cn.gbkexport set

lang=zh_cn.gbk#export set lc_ctype=zh_cn.utf-8#export set

charset=utf-8#***********************************= bashrc end

******************************====

#***********************************= .inputrc ******************************====

# 控制輸入輸出的檔案 jiangxf [2009-10-09 星期五]

"\e[3~": delete-char

# vt

"\e[1~": beginning-of-line

"\e[4~": end-of-line

# kvt

"\e[h": beginning-of-line

"\e[f": end-of-line

"\e[7~": beginning-of-line

"\e[8~": end-of-line

# vt220

"\eoh": beginning-of-line

"\eof": end-of-line

# 關閉bash命令列8位元組字元轉義符的轉換

set convert-meta off

# 使bash命令列支援8位元組字元輸入

set input-meta on

# 使bash命令列支援8位元組字元輸出

set output-meta on

Cygwin下中文輸入

現如今不會用linux程式設計,似乎是件不光彩的事兒。其實幾乎10年前就玩兒過。當時,花一千多大人 民幣 買的ibm硬碟,1.6gb的一半兒裝了個小紅帽5。沒等學會shell程式設計,就放棄了。一幌1 10個世紀過去了。最近要折騰yaws,在windows上非得cygwin不可。沒轍,學吧。教材不錯...

Cygwin中文亂碼問題

直接執行 alias ls ls color show control chars time style long iso 或者把上面的內容加到 etc profile中重啟cygwin即可。為了使使用更方便,推薦增加如下配置資訊 1.編輯使用者home目錄下的檔案.inputc,去除以下幾行的注釋...

cygwin中文亂碼解決

1,在.bashrc profile末尾新增以下內容 讓ls和dir命令顯示中文和顏色 alias ls ls show control chars color alias dir dir n color 設定為中文環境,使提示成為中文 export lang zh cn.gbk 輸出為中文編碼 e...