13

我经常使用 Guake 终端模拟器。这是自切片培育 IMO 以来最好的事情。

但有一件事一直困扰着我,当我想阅读手册页时,输出的默认宽度是终端窗口的宽度,在我的情况下它总是全屏的,所以有点难以阅读。

有没有一种方法可以使 man 命令 a 的输出的默认宽度为 80 个字符,易于阅读?

man 的手册页有这部分:

   MANWIDTH
          If  $MANWIDTH  is set, its value is used as the line length for which manual pages should be formatted.  If it is not set,
          manual pages will be formatted with a line length appropriate to the current terminal (using an ioctl(2) if available, the
          value  of  $COLUMNS,  or  falling  back  to 80 characters if neither is available).  Cat pages will only be saved when the
          default formatting can be used, that is when the terminal line length is between 66 and 80 characters.

但我不知道在哪里改变它。

我尝试添加该行:

人宽 80

到 /etc/manpath.config 和 ~/.bashrc,但没有结果。

4

3 回答 3

19

那是一个环境变量。

尝试:

MANWIDTH=80
export MANWIDTH
man bash

如果您想要永久设置,那么您可以将前两行添加到您的 shell 会话启动脚本或类似脚本中。

于 2015-05-11T16:54:07.087 回答
7

正如其他答案中指出的那样,MANWIDTH正确设置和导出是要走的路。

我会避免对其进行硬编码,否则当您的终端仿真器窗口比该值更窄时,它会溢出/有丑陋的换行符:

NAME
       grep, egrep, fgrep - print lines that match
 patterns

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep [OPTION...] -e PATTERNS ... [FILE...]
       grep [OPTION...] -f PATTERN_FILE ... [FILE.
..]

DESCRIPTION
       grep  searches  for  PATTERNS  in  each  FI
LE.  PATTERNS is one or more
       patterns separated by newline characters, a
nd  grep  prints  each  line
       that  matches a pattern.  Typically PATTERN
S should be quoted when grep
       is used in a shell command.

这是我使用的一个方便的别名:

alias man='MANWIDTH=$((COLUMNS > 80 ? 80 : COLUMNS)) man'

MANWIDTH如果终端窗口比这更宽,则设置为 80,如果COLUMNS更窄,则设置为(终端窗口的当前宽度)。

结果是一个宽窗口:

NAME
       grep, egrep, fgrep - print lines that match patterns

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep [OPTION...] -e PATTERNS ... [FILE...]
       grep [OPTION...] -f PATTERN_FILE ... [FILE...]

DESCRIPTION
       grep  searches  for  PATTERNS  in  each  FILE.  PATTERNS is one or more
       patterns separated by newline characters, and  grep  prints  each  line
       that  matches a pattern.  Typically PATTERNS should be quoted when grep
       is used in a shell command.

产生一个狭窄的窗口:

NAME
       grep,  egrep, fgrep - print lines that
       match patterns

SYNOPSIS
       grep [OPTION...] PATTERNS [FILE...]
       grep  [OPTION...]  -e   PATTERNS   ...
       [FILE...]
       grep  [OPTION...]  -f PATTERN_FILE ...
       [FILE...]

DESCRIPTION
       grep searches  for  PATTERNS  in  each
       FILE.    PATTERNS   is   one  or  more
       patterns    separated    by    newline
       characters,  and grep prints each line
       that  matches  a  pattern.   Typically
       PATTERNS should be quoted when grep is
       used in a shell command.
于 2020-04-03T15:24:35.467 回答
4

您需要将其设置为环境变量。

MANWIDTH=80 man man

在这里工作,并提供了man80 列荣耀的联机帮助页。

如果你想要这个在.bashrc正确的行条目是

export MANWIDTH=80

=注意标志周围没有空格。您可能需要也可能不需要export.

于 2015-05-11T16:50:45.840 回答