Skip to content

Instantly share code, notes, and snippets.

@treyharris
Created April 1, 2019 19:57
Show Gist options
  • Save treyharris/edaaf77fd5c379444dff4080c6510061 to your computer and use it in GitHub Desktop.
Save treyharris/edaaf77fd5c379444dff4080c6510061 to your computer and use it in GitHub Desktop.
# -*-shell-script-*-
# Get zshoptions manpage, advanced to definition of the option. This
# is made more interesting because underscores within option names are
# optional. So to be on the safe side, we stick "_?" between each
# character.
#
# The expansion ${(j:_?:)${(s//)1}} works like this, reading
# right-to-left:
#
# 1. We take the arg $1
# 2. We split it into an array by characters (s//)
# 3. We take that and join each element with "_?" (j:_?:)
[[ $#@ -eq 1 ]] || { echo "Give one argument as a pattern" ; return 1}
name="$1"
PAT=${(j:_?:)${(s//)name}}
LESS="${LESS}+/^ +${PAT}" man zshoptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment