マニュアルページに行番号を追加するには?

マニュアルページに行番号を追加するには?

Linuxでページにman行番号を追加するには?infoマンページを閲覧するために行番号を使用したいと思います。マニュアルページをファイルに書き込んでVimで開くこともできますが、より良い方法はありますか?

ベストアンサー1

からman man

   -P pager, --pager=pager
          Specify  which  output  pager to use.  By default, man uses less
          -s.  This option overrides the $MANPAGER  environment  variable,
          which  in turn overrides the $PAGER environment variable.  It is
          not used in conjunction with -f or -k.

          The value may be a simple command name or a command  with  argu-
          ments, and may use shell quoting (backslashes, single quotes, or
          double quotes).  It may not use pipes to connect  multiple  com-
          mands;  if  you  need that, use a wrapper script, which may take
          the file to display either as an argument or on standard input.

lessしたがって、行番号フラグを使用してポケットベルを指定できます-N

man -P "less -N" 

問題は、manページ幅が端末の列数に基づいて設定されますが、行番号に応じて行の先頭に追加のless文字(スペース+行番号)が追加されるため、出力形式は次のとおりです。ちょっと厄介です。

$ man -P "less -N" man

結果:

      1 MAN(1)                        Manual pager utils                        M
      1 AN(1)
      2 
      3 
      4 
      5 NAME
      6        man - an interface to the on-line reference manuals
      7 
      8 SYNOPSIS
      9        man  [-C  file]  [-d]  [-D]  [--warnings[=warnings]]  [-R encoding
      9 ] [-L
     10        locale] [-m system[,...]] [-M path] [-S list]  [-e  extension]  [-
     10 i|-I]
     11        [--regex|--wildcard]   [--names-only]  [-a]  [-u]  [--no-subpages]
     11   [-P
     12        pager] [-r prompt] [-7] [-E encoding] [--no-hyphenation] [--no-jus
     12 tifi-
     13        cation]  [-p  string]  [-t]  [-T[device]]  [-H[browser]] [-X[dpi]]
     13  [-Z]
     14        [[section] page ...] ...

したがって、環境変数を変更して、数字からMANWIDTH7文字(行プレフィックスの幅)を減算して、ページの幅をより短くフォーマットすることができます。lessCOLUMNSman

$ MANWIDTH=$(( $COLUMNS -7 )) man -P "less -N" man

結果:

      1 MAN(1)                     Manual pager utils                     MAN(1)
      2 
      3 
      4 
      5 NAME
      6        man - an interface to the on-line reference manuals
      7 
      8 SYNOPSIS
      9        man [-C file] [-d] [-D] [--warnings[=warnings]] [-R encoding] [-L
     10        locale] [-m system[,...]] [-M  path]  [-S  list]  [-e  extension]
     11        [-i|-I]  [--regex|--wildcard] [--names-only] [-a] [-u] [--no-sub-
     12        pages] [-P pager] [-r prompt] [-7]  [-E  encoding]  [--no-hyphen-
     13        ation]   [--no-justification]   [-p   string]  [-t]  [-T[device]]
     14        [-H[browser]] [-X[dpi]] [-Z] [[section] page ...] ...

おすすめ記事