Skip to content

Instantly share code, notes, and snippets.

@kljohann
Last active December 5, 2018 21:04
Show Gist options
  • Save kljohann/e5c9d5919e70bce9b85ea79e3ed16e96 to your computer and use it in GitHub Desktop.
Save kljohann/e5c9d5919e70bce9b85ea79e3ed16e96 to your computer and use it in GitHub Desktop.
#!/bin/bash
main () {
declare expression="^EXAMPLE"
declare -a args
args=("$@")
if (( $# == 0 )); then
cat >&2 <<END
Usage: $0 [<args>...] [<expr>]
args: Arguments to pass to man.
expr: Command line argument to search for.
Defaults to jump to the "EXAMPLE" section.
Will open the man page in less and search for the specified
expression at the beginning of lines.
-> Just press "n" until you find what you are looking for!
xamples:
• How does the -name option of find work?
> $0 find -name
• Can you give me some examples for using the find command?
> $0 find
• What does "%e" in printf() do?
> $0 3 printf e
END
return 1
elif (( $# >= 2 )); then
# Extract expression from last argument.
expression="^[[:blank:]]*${args[-1]}"
unset args[-1]
fi
PAGER="less -g -s '+/${expression}'" man "${args[@]}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment