Created
March 31, 2019 07:22
-
-
Save giper45/cdc51407149813ba77e30b365c11a134 to your computer and use it in GitHub Desktop.
manopt (https://stackoverflow.com/questions/19198721/is-there-a-way-to-look-for-a-flag-in-a-man-page)
This file contains hidden or 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
# SYNOPSIS | |
# manopt command opt | |
# | |
# DESCRIPTION | |
# Returns the portion of COMMAND's man page describing option OPT. | |
# Note: Result is plain text - formatting is lost. | |
# | |
# OPT may be a short option (e.g., -F) or long option (e.g., --fixed-strings); | |
# specifying the preceding '-' or '--' is OPTIONAL - UNLESS with long option | |
# names preceded only by *1* '-', such as the actions for the `find` command. | |
# | |
# Matching is exact by default; to turn on prefix matching for long options, | |
# quote the prefix and append '.*', e.g.: `manopt find '-exec.*'` finds | |
# both '-exec' and 'execdir'. | |
# | |
# EXAMPLES | |
# manopt ls l # same as: manopt ls -l | |
# manopt sort reverse # same as: manopt sort --reverse | |
# manopt find -print # MUST prefix with '-' here. | |
# manopt find '-exec.*' # find options *starting* with '-exec' | |
manopt() { | |
local cmd=$1 opt=$2 | |
[[ $opt == -* ]] || { (( ${#opt} == 1 )) && opt="-$opt" || opt="--$opt"; } | |
man "$cmd" | col -b | awk -v opt="$opt" -v RS= '$0 ~ "(^|,)[[:blank:]]+" opt "([[:punct:][:space:]]|$)"' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment