0%

[转]Mac配置中文man手册

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

man手册对于我们在Mac或Linux系统下开发起着至关重要的作用,今天我们就来看一下如何在Mac系统下安装Man手册。

大纲

  • 安装软件依赖
  • 编译安装man手册
  • 修改配置文件
  • 解决乱码问题

软件依赖

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

可以通过homebrew自行安装:

1
2
3
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 手册配置文件

1
sudo vim /etc/man.conf

修改配置文件,如下:

1
2
3
4
5
6
7
8

...
MANPATH /usr/local/share/man #line 44
MANPATH /usr/local/share/man/zh_CN #添加中文手册路径
...


:wq

可以通过下面的命令查看是否中文文档已经加载

1
man -aw

如果出现下面的信息表示已加载

1
/usr/local/share/man:/usr/share/man:/usr/local/share/man/zh_CN         #已经加载

查看中文文档

执行下面的命令:

1
man -aw ls            <= 查看有几个中文文档

输出结果:

1
2
/usr/share/man/man1/ls.1                 <= 默认文档
/usr/local/share/man/zh_CN/man1/ls.1 <= 中文文档

查看文档内容

1
man -a ls             <= 查看文档内容

输出结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)。

1
brew install groff

安装完成后,配置man.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
  • 本文作者: 音视跳动-李超 [avdance@163.com]
  • 本文链接: https://blog.avdancedu.com/a77533/
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!

欢迎关注我的其它发布渠道