Suche nach einer bestimmten Option in einer Manpage

2379
mgalgs

Ich finde oft maneinen Befehl, nur um eine bestimmte Option zu lernen. Die meiste Zeit kann ich nach der Option suchen, es sei denn, es ist ungefähr so, ffmpegoder gccich muss ungefähr 40 Übereinstimmungen durchlaufen, bis ich zur eigentlichen Beschreibung der Option komme.

Manchmal kann ich Glück haben und nach dem Wort "Optionen" suchen, um näher zu kommen und es dann zu verfeinern, aber es wäre schön, wenn ich direkt zu der fraglichen Option springen könnte. Es wäre cool, wenn es ein Tool gibt, das die Optionen auslotet und eine Datenbank aufbaut, auf der Sie suchen können, aber nachdem ich das Groff-Markup für ein paar Seiten durchgesehen hatte, habe ich festgestellt, dass dies nur eine Best-Vermutung wäre Aufgrund des Mangels an Metainformationen in Groff Markup ... In meiner idealen Welt würde der Modus "Frau" in Emacs die Suche nach bestimmten Optionen unterstützen ... :)

Irgendwelche Tipps, um direkt zu einer bestimmten Option in einer Manpage zu springen?

14

2 Antworten auf die Frage

5
Mikel

Hier ist mein Skript, um es zu tun. Es heißt er .

$ 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. 

Wenn Sie jedoch keinen Zugriff auf ein solches Skript haben, führen Sie es einfach aus lessund geben Sie /^ *-option(Leerzeichen beachten) ein. Geben Sie beispielsweise in die gccManpage ein, /^ *-dDEnterum die Dokumentation für die -dDOption zu suchen .

Dies funktioniert, weil die Option normalerweise am Anfang der Zeile angezeigt wird.

Klappt wunderbar! Vielen Dank! mgalgs vor 13 Jahren 0
Stellen Sie sich einen großen bärtigen Bärenmann vor, der Ihre Zehen dafür küsst! sepehr vor 9 Jahren 1
Ha ha! Vielen Dank! Beachten Sie auch, dass ich das Skript in "er" umbenannt habe, wie in "kurze Hilfe". Die neueste Version ist auf [github] (https://github.com/mikelward/scripts/blob/master/he). Mikel vor 9 Jahren 0
2
Dennis Williamson

Diese Funktion verwende ich. Ich nenne es "mans" für "man search".

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

Verwendungszweck:

$ mans ^OPTIONS grep find xargs 
Süss! Nicht genau die "ideale" Nachschlagetabelle, auf die ich gehofft hatte, aber immer noch sehr nützlich. Vielen Dank. mgalgs vor 13 Jahren 0
Wie unten erwähnt, ist das, wonach Sie suchen, die meiste Zeit nach einem Einzug am Anfang der Zeile, so dass das Muster normalerweise wie "mans" aussieht. * *' `. Siehe meine Antwort für weitere Details. Mikel vor 13 Jahren 1