Skip to content

Instantly share code, notes, and snippets.

@kljohann
Created July 29, 2018 10:20
Show Gist options
  • Save kljohann/588a3d533912cc3b7757ecd98667849e to your computer and use it in GitHub Desktop.
Save kljohann/588a3d533912cc3b7757ecd98667849e to your computer and use it in GitHub Desktop.
eg.zsh
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