更改man命令输出的宽度

时间:2015-05-11 16:45:00

标签: linux shell terminal man terminal-emulator

我经常使用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.

但我无法弄清楚在哪里改变它。

我尝试添加一行:

  

MANWIDTH 80

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

2 个答案:

答案 0 :(得分:4)

如其他答案所指出的那样,正确设置和导出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,则将COLUMNS设置为80;如果终端窗口的宽度小于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. 设置为<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth"> <thead> <tr> <th rowspan="2" class="is-size-7 has-text-centered">Name</th> <th rowspan="2" class="is-size-7 has-text-centered">Unit</th> <th rowspan="2" class="is-size-7 has-text-centered">Value in BTC</th> <th rowspan="2" class="is-size-7 has-text-centered">Type</th> </tr> </thead> {% for exchange in data_exchange.values %} {% load humanize %} <tbody> <tr> <th class="is-size-7 has-text-centered"><strong>{{ exchange.name }}</strong></th> <td class="has-text-centered">{{ exchange.unit }}</td> <td class="has-text-centered">{{ exchange.value|intword|intcomma }}</td> <td class="has-text-centered">{{ exchange.type }}</td> </tr> {% endfor %} </tbody> </table>

在宽窗口中显示结果:

<link rel="preload" as="worker">

结果在一个狭窄的窗口中

<link rel="prefetch">

答案 1 :(得分:3)

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

MANWIDTH=80 man man

在这里工作,并提供80列荣耀中man的联机帮助页。

如果您想在.bashrc中找到正确的行条目

export MANWIDTH=80

请注意=符号周围缺少空格。您可能需要export