shell 更改man命令输出的宽度

sr4lhrrt  于 12个月前  发布在  Shell
关注(0)|答案(4)|浏览(158)

我经常使用Guake终端模拟器。这是自切片繁殖以来最好的东西。
但有一件事一直困扰着我,当我想阅读手册页时,输出的默认宽度是终端窗口的宽度,在我的情况下总是全屏,所以阅读起来有点困难。
有没有一种方法可以使man命令输出的默认宽度为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,但没有结果。

unftdfkk

unftdfkk1#

这是一个环境变量。
试试看:

MANWIDTH=80
export MANWIDTH
man bash

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

mm5n2pyu

mm5n2pyu2#

正如其他答案中所指出的,正确设置和导出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宽,则MANWIDTH设置为80;如果终端窗口比COLUMNS窄,则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.
e5nqia27

e5nqia273#

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

MANWIDTH=80 man man

在这里工作,并提供了man在80列荣耀的手册页。
如果您希望在.bashrc中执行此操作,则正确的行条目为

export MANWIDTH=80

注意=符号周围缺少空格。你可能需要也可能不需要export

nhhxz33t

nhhxz33t4#

人宽=80人bc
这是按需控制man页面宽度的简单方法。它将覆盖在其他地方定义的MANWIDTH的值。要永久更改man页面宽度,请在shell配置文件中设置环境变量MANWIDTH。这样,就不需要在man命令之前始终使用MANWIDTH=80

相关问题