Last active
December 5, 2018 21:04
-
-
Save kljohann/e5c9d5919e70bce9b85ea79e3ed16e96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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