在手册页中搜索特定选项


14

我经常发现自己man只是为了了解一个特定的选项。大多数时候我可以搜索到这个选项就好了,除非它是类似的ffmpeggcc我需要逐步完成大约40场比赛,直到我得到选项的实际描述...

有时我可以幸运地搜索“选项”这个词来接近然后从那里进行改进,但如果我能够可靠地直接跳到有问题的选项那就太好了。如果有一个工具可以解析选项并构建一个可以进行搜索的数据库,那将会很酷,但是在看了几页的groff标记之后,我确定它只是一个最好的猜测工作由于groff标记中缺少元信息...在我的理想世界中,emacs中的女性模式将支持搜索特定选项... :)

有关直接跳到手册页中特定选项的提示吗?

Answers:


5

这是我的脚本。这叫

$ he cp    
SYNOPSIS
       cp [OPTION]... [-T] SOURCE DEST
       cp [OPTION]... SOURCE... DIRECTORY
       cp [OPTION]... -t DIRECTORY SOURCE...

$ he gcc -dD
       -dD Dump all macro definitions, at the end of preprocessing, in addition to normal output.

$ he rsync -v
        -v, --verbose               increase verbosity

$ he bash getopts
       getopts optstring name [args]
              getopts is used by shell procedures to parse positional parameters.  optstring contains the option characters to be recognized; if a character is  followed  by  a  colon,  the  option  is
              expected  to  have  an  argument, which should be separated from it by white space.  The colon and question mark characters may not be used as option characters.  Each time it is invoked,
              getopts places the next option in the shell variable name, initializing name if it does not exist, and the index of the next argument to be processed into the variable OPTIND.  OPTIND  is
              initialized  to  1 each time the shell or a shell script is invoked.  When an option requires an argument, getopts places that argument into the variable OPTARG.  The shell does not reset
              OPTIND automatically; it must be manually reset between multiple calls to getopts within the same shell invocation if a new set of parameters is to be used.

              When the end of options is encountered, getopts exits with a return value greater than zero.  OPTIND is set to the index of the first non-option argument, and name is set to ?.

              getopts normally parses the positional parameters, but if more arguments are given in args, getopts parses those instead.

              getopts can report errors in two ways.  If the first character of optstring is a colon, silent error reporting is used.  In normal operation diagnostic messages are printed  when  invalid
              options or missing option arguments are encountered.  If the variable OPTERR is set to 0, no error messages will be displayed, even if the first character of optstring is not a colon.

              If  an  invalid  option  is  seen, getopts places ? into name and, if not silent, prints an error message and unsets OPTARG.  If getopts is silent, the option character found is placed in
              OPTARG and no diagnostic message is printed.

              If a required argument is not found, and getopts is not silent, a question mark (?) is placed in name, OPTARG is unset, and a diagnostic message is printed.  If getopts is silent, then  a
              colon (:) is placed in name and OPTARG is set to the option character found.

              getopts returns true if an option, specified or unspecified, is found.  It returns false if the end of options is encountered or an error occurs.

但是如果您无法访问这样的脚本,只需运行less,然后键入/^ *-option(注意空格),例如,在gcc手册页中键入/^ *-dDEnter以查找该-dD选项的文档。

这是有效的,因为该选项通常出现在行的开头。


1
想象一下,一个大胡子的熊男人亲吻你的脚趾!
sepehr 2014年

哈哈!谢谢!另请注意,我将脚本重命名he为“简短帮助”。最新版本是在github上
Mikel

2

这是我使用的功能。我称之为“男人搜索”的“勒芒”。

mans ()
{
    local pages string;
    if [[ -n $2 ]]; then
        pages=(${@:2});
        string="$1";
    else
        pages=$1;
    fi;
    man ${2:+--pager="less -p \"$string\" -G"} ${pages[@]}
}

用法:

$ mans ^OPTIONS grep find xargs

甜!不完全是我希望的“理想”查找表类型解决方案,但仍然非常有用。谢谢。
mgalgs 2011年

1
如下所述,大多数时候你想要的是在一些缩进之后的行的开头,所以模式通常看起来像mans '^ *<something>' <page>。有关详细信息,请参阅我的回答
Mikel
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.