[轉]Mac 配置中文man手冊

轉自: http://www.jackaiup.com/index/detail?id=10234

軟件依賴

  • autotools (autoconf, automake)
  • python3
  • opencc 1.x

可以通過homebrew自行安裝:

brew install autotools
brew install python3
brew install opencc

編譯安裝

git clone https://github.com/man-pages-zh/manpages-zh #下載文件
cd manpages-zh
autoreconf --install --force #構建configure文件
./configure
make
make install #需要超級用戶權限

添加手冊路徑

打開 man 手冊配置文件

sudo vim /etc/man.conf

修改配置文件,如下:

 
...
MANPATH /usr/local/share/man              #line 44
MANPATH /usr/local/share/man/zh_CN        #添加中文手冊路徑
...
 
 
:wq

可以通過下面的命令查看是否中文文檔已經加載

man -aw     

如果出現下面的信息表示已加載

/usr/local/share/man:/usr/share/man:/usr/local/share/man/zh_CN         #已經加載

查看中文文檔

執行下面的命令:

man -aw ls            <= 查看有幾個中文文檔

輸出結果:

/usr/share/man/man1/ls.1                 <= 默認文檔
/usr/local/share/man/zh_CN/man1/ls.1     <= 中文文檔

查看文檔內容

man -a ls             <= 查看文檔內容

輸出結果:

LS(1)                     BSD General Commands Manual                    LS(1)
NAME
     ls — list directory contents
SYNOPSIS
     ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1] [file ...]
DESCRIPTION
     For each operand that names a file of a type other than directory, ls displays its name as
     well as any requested, associated information.  For each operand that names a file of type
     directory, ls displays the names of files contained within that directory, as well as any
     requested, associated information.
     If no operands are given, the contents of the current directory are displayed.  If more than
     one operand is given, non-directory operands are displayed first; directory and non-direc‐
     tory operands are sorted separately and in lexicographical order.
     The following options are available:
     -@      Display extended attribute keys and sizes in long (-l) output.
     -1      (The numeric digit “one”.)  Force output to be one entry per line.  This is the
     ...
    按【q】進入中文文檔

LS(1)                                General Commands Manual                                LS(1)
NAME
       ls, dir, vdir - 列目錄內容
提要
       ls [選項] [文件名...]
       POSIX 標準選項: [-CFRacdilqrtu1]
GNU 選項 (短格式):
       [-1abcdfgiklmnopqrstuxABCDFGLNQRSUX]  [-w  cols]  [-T  cols]  [-I  pattern]  [--full-time]
       [--format={long,verbose,commas,across,vertical,single-column}]
       [--sort={none,time,size,extension}]               [--time={atime,access,use,ctime,status}]
       [--color[={none,auto,always}]] [--help] [--version] [--]
描述( DESCRIPTION )
       程序ls先列出非目錄的文件項,然後是每一個目錄中的“可顯示”文件。如果
       沒有選項之外的參數【譯註:即文件名部分爲空】出現,缺省爲   "."   (當前目錄)。  選項“  -d
       ”使得目錄與非目錄項同樣對待。除非“ -a ” 選項出現,文 件名以“.”開始的文件不屬“可顯示”文件。
       以當前目錄爲準,每一組文件(包括非目錄文件項,以及每一內含文件的目錄)分
       別按文件名比較順序排序。如果“-l”選項存在,每組文件前顯示一摘要行:
       ...
【注】默認進入英文文檔,按【q】可進入中文文檔,再次按【q】則退出文檔

解決亂碼

如果系統的groff版本太低,文檔可能出現亂碼,可以將groff更新到最新版本(1.22.3,可能的話請使用尚未發佈的 1.22.4)。

brew install groff

安裝完成後,配置man.conf

sudo vim /etc/man.conf
 
...
#修改NROFF配置如下(將UTF8編碼的MAN頁面通過轉碼而被groff識別)
#line 95
 
NROFF preconv -e utf8 | /usr/local/bin/groff -Wall -mtty-char -Tutf8 -mandoc -c  
 
...
 
#修改PAGER配置如下(這樣可以避免MAN手冊頁面中的ANSI Escape字符序列干擾(用於控制顯示粗體等格式))
#line 106
 
PAGER /usr/bin/less -isR
...
 
:wq
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章