Поиск определенной опции на странице руководства

2305
mgalgs

Я часто нахожу manкоманду, чтобы узнать об одном конкретном варианте. Большую часть времени я могу искать вариант просто отлично, если только это не что-то вроде ffmpegили gccкогда мне нужно пройти около 40 совпадений, пока я не доберусь до фактического описания варианта ...

Иногда мне везет, и я ищу слово «опции», чтобы подобраться ближе, а затем уточнить его оттуда, но было бы неплохо, если бы я мог надежно перейти прямо к рассматриваемому варианту. Было бы здорово, если бы существовал инструмент, который мог бы анализировать параметры и создать базу данных, по которой вы могли бы выполнять поиск, но, посмотрев на разметку groff для нескольких страниц, я определил, что это будет только попытка угадать из-за отсутствия мета-информации в разметке groff ... В моем идеальном мире женский режим в emacs будет поддерживать поиск определенных опций ... :)

Любые советы по переходу прямо к определенной опции на странице руководства?

14

2 ответа на вопрос

5
Mikel

Вот мой сценарий, чтобы сделать это. Это называется он .

$ 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опции.

Это работает, потому что опция обычно появляется в начале строки.

Работает как шарм! Спасибо! mgalgs 13 лет назад 0
Представь себе большого бородатого медведя, целующего твои пальцы за это! sepehr 9 лет назад 1
Ха ха! Спасибо! Также обратите внимание, что я переименовал скрипт в «он», как в «краткой справке». Последняя версия находится на [github] (https://github.com/mikelward/scripts/blob/master/he) Mikel 9 лет назад 0
2
Dennis Williamson

Это функция, которую я использую. Я называю это «мужчинами» для «поиска человека».

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

Использование:

$ mans ^OPTIONS grep find xargs 
Милая! Не совсем «идеальное» решение типа таблицы поиска, на которое я надеялся, но все же очень полезное. Благодарю. mgalgs 13 лет назад 0
Как отмечается ниже, большую часть времени вы ищете в начале строки после некоторого отступа, поэтому шаблон обычно будет выглядеть как `mans '^ *' `. Смотрите мой ответ для более подробной информации. Mikel 13 лет назад 1

Похожие вопросы