Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: 119cb0d962
Fetching contributors…

Cannot retrieve contributors at this time

executable file 49 lines (40 sloc) 0.907 kb
#!/bin/bash
#
# http://man.cx manpage extractor
# requires: xmllint (libxml2)
#
BASEURL='http://man.cx'
XMLLINT=('xmllint' '--html')
XPATH_EXPR='//*[@id="manpage"]'
usage() {
printf "Usage: %s [section] manpage" "${0##*/}" >&2
}
# less gets color, else its a NOOP
if [[ ${PAGER:-less} = less ]]; then
colorify() {
sed '/^[[:upper:][:blank:]]\+$/{
s/^/'"$LESS_TERMCAP_md"'/
s/$/'"$LESS_TERMCAP_ue"'/
}'
}
else
colorify() { cat; }
fi
case $# in
1) PAGE=$1 ;;
2) SECTION="($1)"
PAGE=$2 ;;
*) usage; exit 1 ;;
esac
# if found locally, exit
man ${SECTION//[^[:digit:]]/} $PAGE 2>/dev/null && exit
manpage=$(curl -s $BASEURL/$PAGE$SECTION |
"${XMLLINT[@]}" --xpath "$XPATH_EXPR" - 2>/dev/null |
w3m -T text/html |
colorify)
if [[ $manpage ]]; then
"${PAGER:-less}" <<< "$manpage"
else
printf "No mancx entry for %s\n" "$PAGE"
exit 1
fi
Jump to Line
Something went wrong with that request. Please try again.