Created
July 29, 2018 10:20
-
-
Save kljohann/588a3d533912cc3b7757ecd98667849e to your computer and use it in GitHub Desktop.
eg.zsh
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
eg () { | |
(( $+1 )) || { | |
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. | |
Examples: | |
$0 find | |
$0 less -s | |
$0 1 less -s | |
$0 zshall HIST_IGNORE_SPACE | |
$0 zshall fc | |
END | |
return 1 | |
} | |
local expr='^EXAMPLE' | |
local -a args | |
args=("$@") | |
(( $+2 )) && { | |
expr="^[[:blank:]]*${@[-1]}" | |
args=("${@[1,-2]}") | |
} | |
PAGER="less -g -s '+/$expr'" man "${=args}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment