Created
December 4, 2009 16:39
-
-
Save rphillips/249134 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# freebsdman - manpage fetcher from www.freebsd.org | |
# | |
# Author: Mohan Raman | |
# License: Whatever license FreeBSD is telling to access | |
# their servers. | |
# | |
print_values() | |
{ | |
VALUES=" | |
apropos: | |
======= | |
0 Disable | |
1 Enable | |
section: | |
======= | |
`curl http://www.freebsd.org/cgi/man.cgi 2>&1 | | |
sed -n -e'/<select name="sektion">/,/<\/select>/p' | | |
cut -d'>' -f2 | | |
cut -d'<' -f1 | | |
grep -v '^\$' | | |
sed -e"s/^All.*/0 - &/g"` | |
distros: | |
======= | |
`curl http://www.freebsd.org/cgi/man.cgi 2>&1 | | |
sed -n -e'/<select name="manpath">/,/<\/select>/p' | | |
cut -d'>' -f2 | | |
cut -d'<' -f1 | | |
grep -v '^\$'` | |
format: | |
======= | |
`curl http://www.freebsd.org/cgi/man.cgi 2>&1 | | |
sed -n -e'/<select name="format">/,/<\/select>/p' | | |
cut -d'>' -f2 | | |
cut -d'<' -f1 | | |
grep -v '^\$'` | |
" | |
echo "${VALUES}" | |
} | |
default_manpath() | |
{ | |
curl http://www.freebsd.org/cgi/man.cgi 2>&1 | | |
sed -n -e'/<select name="manpath">/,/<\/select>/p' | | |
cut -d'>' -f2 | | |
cut -d'<' -f1 | | |
grep -v '^\$' | | |
grep 'FreeBSD [^P]' | | |
tail -1 | | |
tr ' ' '+' | | |
sed -e's/\//%2F/g' | |
} | |
USAGE="USAGE: | |
freebsdman [-a 0|1] [-s section] [-d distro] | |
[-f format] [-o] [-h] | |
" | |
HELP="${USAGE} | |
DESCRIPTION: | |
-a 0|1 do 'apropos' search(1-enable, 0-disable) | |
-s section select man section(1-8) | |
-d distro distribution name | |
-f format appropriate format | |
-o list available values for other options. | |
-h print this help | |
EXAMPLES: | |
$ freebsdman ps | |
will display man page of 'ps' command from latest | |
FreeBSD version in terminal(format: ascii). | |
$ freebsdman -d 'solaris' -f pdf mpstat > mpstat.pdf | |
will generate 'mpstat.pdf' file which contains | |
manual page of 'mpstat' from solaris. | |
$ freebsdman -o | |
will list all valid values for 'freebsdman' options. | |
$ freebsdman -d 'x11' X | |
will display 'X' manual (note: manual will not be displayed | |
without -d 'x11' option) | |
" | |
APROPOS="0" | |
SEKTION="0" | |
FORMAT="ascii" | |
while getopts 'a:s:d:f:oh' OPTIONS | |
do | |
case "${OPTIONS}" | |
in | |
a) APROPOS="${OPTARG}";; | |
s) SEKTION="${OPTARG}";; | |
d) MANPATH=`echo "${OPTARG}" | tr ' ' '+' | sed -e's/\//%2F/g'`;; | |
f) FORMAT="${OPTARG}";; | |
o) print_values;; | |
h) echo "${HELP}" && exit 0;; | |
\?) echo "${USAGE}" && exit 1;; | |
esac | |
done | |
shift $((OPTIND - 1)) | |
test -z "${*}" && echo "${USAGE}" && exit 1 | |
test -z "${MANPATH}" && MANPATH="`default_manpath`"; | |
for QUERY | |
do | |
QUERY=`echo "${QUERY}" | tr ' ' '+'` | |
COMMAND="http://www.freebsd.org/cgi/man.cgi?" | |
COMMAND="${COMMAND}query=${QUERY}" | |
COMMAND="${COMMAND}&apropos=${APROPOS}" | |
COMMAND="${COMMAND}&sektion=${SEKTION}" | |
COMMAND="${COMMAND}&manpath=${MANPATH}" | |
COMMAND="${COMMAND}&format=${FORMAT}" | |
curl "${COMMAND}" 2>/dev/null | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment