[Surfraw-commits] [surfraw] 01/01: w3_custom_search; new elvi: mdn, phpdoc, mysqldoc, pgdoc
Ian Beckwith
ianb at alioth.debian.org
Mon Sep 30 05:09:39 UTC 2013
This is an automated email from the git hooks/post-receive script.
ianb pushed a commit to branch 2.2.9_release_candidate
in repository surfraw.
commit 35a34b2a833dfcd5bb55f791de5520ad17f9f7f1
Author: Ian Beckwith <ianb at erislabs.net>
Date: Mon Sep 30 06:09:32 2013 +0100
w3_custom_search; new elvi: mdn, phpdoc, mysqldoc, pgdoc
---
ChangeLog | 20 ++++++++++++
README | 14 +++++---
elvi/Makefile.am | 6 +++-
elvi/mdn | 25 ++++++++++++++
elvi/mysqldoc | 65 ++++++++++++++++++++++++++++++++++++
elvi/netbsd | 4 +--
elvi/openbsd | 3 +-
elvi/pgdoc | 87 +++++++++++++++++++++++++++++++++++++++++++++++++
elvi/phpdoc | 25 ++++++++++++++
elvi/piratebay | 2 +-
elvi/slinuxdoc | 4 +--
elvi/worldwidescience | 2 +-
links.IN | 6 +++-
surfraw.IN | 74 +++++++++++++++++++++++++++++++++++++++--
surfraw.conf.IN | 4 +++
15 files changed, 324 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b049661..25f6d5b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2013-09-30 Ian Beckwith <ianb at erislabs.net>
+
+ * new elvi: mdn, mysqldoc, pgdoc, phpdoc
+ * new function: w3_custom_search
+ Is used by elvi that use a generic search engine with (eg) site:
+ or inurl: to narrow down the search.
+ Pass it -s=site -u=url for site: and inurl: args
+ plus the quoted search args
+ * new environment variable: SURFRAW_customsearch_provider
+ to set provider used by w3_custom_search
+ can be set to: google, duckduckgo or ixquick.
+ Currently affects: mysqldoc, netbsd(*), openbsd(*), pgdoc,
+ phpdoc, mysqldoc.
+ (*) = only used by some options of elvi.
+ * new internal variable w3_shquoted_args, contains
+ arguments 'quoted' 'like this' for passing
+ to w3_custom_search
+ * Fixed url-encoding for '\'
+
+
2013-05-07 Ian Beckwith <ianb at erislabs.net>
* new elvi: jquery
diff --git a/README b/README
index 78901eb..9be5683 100644
--- a/README
+++ b/README
@@ -170,7 +170,7 @@ bing -- Search the web using Microsoft's Bing (www.bing.com)
bookfinder -- Search for books using www.bookfinder.com
bugmenot -- Bypass compulsory web registration with bugmenot.com
bugzilla -- Search for bugs on Bugzilla bugtrackers
-cablesearch -- search openports for OpenBSD packages
+cablesearch -- search for leaked diplomatic communications
cia -- Search CIA documents at www.cia.gov
cisco -- Search Cisco documentation (www.cisco.com)
cite -- Search computer science papers (citeseerx.ist.psu.edu)
@@ -210,7 +210,7 @@ fsfdir -- Search the FSF/UNESCO Free Software Directory (directory.fsf.
gcache -- Search the web using Google cache (www.google.com)
genbugs -- Search the Gentoo bug tracker (bugs.gentoo.org)
genportage -- Search gentoo-portage.com for packages
-github -- Search github for code (www.github.com)
+github -- Search GitHub (https://github.com)
google -- Search the web using Google (www.google.com)
gutenberg -- Search for books on Project Gutenberg (gutenberg.org)
imdb -- Search the Internet Movie Database (www.imdb.com)
@@ -224,17 +224,21 @@ leodict -- Search Leo's German <-> English dictionary (dict.leo.org)
lsm -- Search the Linux Software Map
macports -- Search macports packages (macports.org)
mathworld -- Search Wolfram MathWorld
+mdn -- Search the mozilla developer network (developer.mozilla.org)
mininova -- Search the mininova bittorent source.
musicbrainz -- Search MusicBrainz (musicbrainz.org)
+mysqldoc -- Search mysql documentation (dev.mysql.com)
netbsd -- Search NetBSD related information (www.netbsd.org)
ntrs -- Search the NASA Technical Report Server
openbsd -- Search OpenBSD related information (www.openbsd.org)
openports -- search openports for OpenBSD packages
opensearch -- Search an OpenSearch-enabled website
pasearch -- Search the unofficial Penny Arcade archives (pipefour.org/pa)
+pgdoc -- Search postgres documentation (www.pgdoc.com)
pgpkeys -- Search the PGP key database
+phpdoc -- Search php documentation (php.net)
pin -- Search Pinboard bookmarks (http://pinboard.in)
-piratebay -- Search thepiratebay.org for torrents
+piratebay -- Search The Pirate Bay (http://thepiratebay.org)
priberam -- Look up word in Priberam online dictionary (www.priberam.pt/dlpo)
pubmed -- Search medical/molbio databases (www.ncbi.nlm.nih.gov)
rae -- Busca en el diccionario de la Real Academia de la Lengua Española (Spanish Dictionary)
@@ -254,7 +258,7 @@ stack -- Search Stack Overflow
stockquote -- Get a single stock quote (multiple providers)
sunonesearch -- Search Sun One Search (onesearch.sun.com)
thesaurus -- Look up word in Merriam-Webster's Thesaurus (www.m-w.com)
-translate -- Translate human languages (various providers)
+translate -- Translate human languages
urban -- Search urbandictionary.com for a definition
w3css -- Validate a CSS URL with the w3c CSS validator (jigsaw.w3.org/css-validator)
w3html -- Validate a web page URL with the w3c validator (validator.w3.org)
@@ -266,7 +270,7 @@ wetandwild -- Real time weather information (many sources)
wikipedia -- Search the free encyclopedia wikipedia
woffle -- Search the web using Woffle (localhost:8080)
wolfram -- Ask questions of the computational knowledge engine
-worldwidescience -- Search for science with www.worldwidescience.org
+worldwidescience -- Search for science with www.worldwidescience.org
yahoo -- Search Yahoo categories (www.yahoo.com)
yandex -- Search the web using Yandex (yandex.ru)
youtube -- Search YouTube (www.youtube.com)
diff --git a/elvi/Makefile.am b/elvi/Makefile.am
index b54553f..9925d77 100644
--- a/elvi/Makefile.am
+++ b/elvi/Makefile.am
@@ -72,17 +72,21 @@ dist_elvi_SCRIPTS = \
lsm \
macports \
mathworld \
+ mdn \
mininova \
musicbrainz \
+ mysqldoc \
netbsd \
ntrs \
openbsd \
openports \
opensearch \
pasearch \
+ pgdoc \
+ pgpkeys \
+ phpdoc \
pin \
piratebay \
- pgpkeys \
priberam \
pubmed \
rae \
diff --git a/elvi/mdn b/elvi/mdn
new file mode 100755
index 0000000..50c0108
--- /dev/null
+++ b/elvi/mdn
@@ -0,0 +1,25 @@
+#!/bin/sh
+# ianb at erislabs.net 20130923
+# elvis: mdn -- Search the mozilla developer network (developer.mozilla.org)
+. surfraw || exit 1
+
+w3_usage_hook () {
+ cat <<EOF
+Usage: $w3_argv0 [search words]...
+Description:
+ Surfraw search the mozilla developer network (developer.mozilla.org)
+EOF
+ w3_global_usage
+}
+
+w3_config
+w3_parse_args "$@"
+if test -z "$w3_args"
+then
+ w3_browse_url "http://developer.mozilla.org"
+else
+ escaped_args=`w3_url_of_arg $w3_args`
+ w3_browse_url "http://developer.mozilla.org/en-US/search?q=${escaped_args}"
+fi
+
+
diff --git a/elvi/mysqldoc b/elvi/mysqldoc
new file mode 100755
index 0000000..bdd5d5b
--- /dev/null
+++ b/elvi/mysqldoc
@@ -0,0 +1,65 @@
+#!/bin/sh
+# ianb at erislabs.net 20130923
+# elvis: mysqldoc -- Search mysql documentation (dev.mysql.com)
+. surfraw || exit 1
+
+w3_config_hook () {
+ def SURFRAW_mysqldoc_version 5.5
+}
+
+w3_usage_hook () {
+ cat <<EOF
+Usage: $w3_argv0 [options] [search words]...
+Description:
+ Surfraw search mysql documentation (dev.mysql.com)
+Local options:
+ -a Search all versions/docs
+ -v=VERSION Search docs for mysql version VERSION
+ Default: $SURFRAW_mysqldoc_version
+ Environment: SURFRAW_mysqldoc_version
+ (NB: doesn't really work with
+ SURFRAW_customsearch_provider=ixquick )
+EOF
+ w3_custom_search_usage
+ w3_global_usage
+}
+
+w3_parse_option_hook () {
+ opt="$1"
+ optarg="$2"
+ case "$opt" in
+ -a) setopt SURFRAW_mysqldoc_version "all" ;;
+ -v*=*) setopt SURFRAW_mysqldoc_version "$optarg" ;;
+ *) return 1 ;;
+ esac
+ return 0
+}
+
+w3_config
+w3_parse_args "$@"
+
+if test -z "$w3_args"
+then
+ case "$SURFRAW_mysqldoc_version" in
+ all) inurl="/doc/" ;;
+ *5.7*) inurl="/doc/refman/5.7/en/" ;;
+ *5.6*) inurl="/doc/refman/5.6/en/" ;;
+ *5.5*) inurl="/doc/refman/5.5/en/" ;;
+ *5.0*) inurl="/doc/refman/5.0/en/" ;;
+ *[34]*) inurl="/doc/refman/4.1/en/" ;;
+ *) inurl="/doc/"
+ esac
+ w3_browse_url "http://dev.mysql.com${inurl}"
+else
+ case "$SURFRAW_mysqldoc_version" in
+ all) inurl="-u=doc" ;;
+ *5.7*) inurl="-u=doc -u=refman -u=5.7" ;;
+ *5.6*) inurl="-u=doc -u=refman -u=5.6" ;;
+ *5.5*) inurl="-u=doc -u=refman -u=5.5" ;;
+ *5.0*) inurl="-u=doc -u=refman -u=5.0" ;;
+ *[34]*) inurl="-u=doc -u=refman -u=4.1" ;;
+ *) inurl="-u=doc" ;;
+ esac
+
+ w3_custom_search -s=dev.mysql.com $inurl "$w3_shquoted_args"
+fi
diff --git a/elvi/netbsd b/elvi/netbsd
index 875a9eb..0ec7f96 100755
--- a/elvi/netbsd
+++ b/elvi/netbsd
@@ -75,13 +75,13 @@ if ok SURFRAW_netbsd_mail; then
if test -z "$escaped_args"; then
w3_browse_url "http://mail-index.netbsd.org/"
else
- w3_browse_url "http://www.google.com/search?q=${escaped_args}%20site%3Amail-index.netbsd.org&num=$SURFRAW_results"
+ w3_custom_search -s=mail-index.netbsd.org "$w3_shquoted_args"
fi
exit $?
fi
if test -z "$escaped_args"; then
w3_browse_url "http://www.netbsd.org/"
else
- w3_browse_url "http://www.google.com/search?q=${escaped_args}%20site%3Anetbsd.org&num=$SURFRAW_results"
+ w3_custom_search -s=netbsd.org "$w3_shquoted_args"
fi
exit $?
diff --git a/elvi/openbsd b/elvi/openbsd
index eec85a2..e2ac3dc 100755
--- a/elvi/openbsd
+++ b/elvi/openbsd
@@ -36,6 +36,7 @@ Examples:
$w3_argv0 -misc supermicro Search misc mailing list for supermico
$w3_argv0 -tech SMP Search tech mailing list for SMP
EOF
+ w3_custom_search_usage
w3_global_usage
}
@@ -96,6 +97,6 @@ fi
if test -z "$escaped_args"; then
w3_browse_url "http://www.openbsd.org/"
else
- w3_browse_url "http://www.google.com/search?q=site:openbsd.org+${escaped_args}"
+ w3_custom_search -s=openbsd.org "$w3_shquoted_args"
fi
exit $?
diff --git a/elvi/pgdoc b/elvi/pgdoc
new file mode 100755
index 0000000..da811f2
--- /dev/null
+++ b/elvi/pgdoc
@@ -0,0 +1,87 @@
+#!/bin/sh
+# ianb at erislabs.net 20130923
+# elvis: pgdoc -- Search postgres documentation (www.pgdoc.com)
+. surfraw || exit 1
+
+w3_config_hook () {
+ def SURFRAW_pgdoc_version 9.1
+ defyn SURFRAW_pgdoc_comments no
+}
+
+w3_usage_hook () {
+ cat <<EOF
+Usage: $w3_argv0 [options] [search words]...
+Description:
+ Surfraw search the Postgresql documentation (www.postgresql.org)
+Local options:
+ -c Search in comments too
+ -v=VERSION Search in version VERSION
+ Default: $SURFRAW_pgdoc_version
+ Environment: SURFRAW_pgdoc_version
+ (NB: doesn't really work with
+ SURFRAW_customsearch_provider=ixquick )
+EOF
+ w3_custom_search_usage
+ w3_global_usage
+}
+
+w3_parse_option_hook () {
+ opt="$1"
+ optarg="$2"
+ case "$opt" in
+ -c*) setoptyn SURFRAW_pgdoc_comments 1 ;;
+ -v*=*) setopt SURFRAW_pgdoc_version "$optarg" ;;
+ *) return 1 ;;
+ esac
+ return 0
+}
+
+w3_config
+w3_parse_args "$@"
+
+if test -z "$w3_args"
+then
+ case "$SURFRAW_pgdoc_version" in
+ all) inurl="/docs/" ;;
+ *9.3*) inurl="/docs/9.3/" ;;
+ *9.2*) inurl="/docs/9.2/" ;;
+ *9.1*) inurl="/docs/9.1/" ;;
+ *9.0*) inurl="/docs/9.0/" ;;
+ *8.4*) inurl="/docs/8.4/" ;;
+ *) inurl="/docs/" ;;
+ esac
+
+ if [ "$SURFRAW_pgdoc_version" != all ]
+ then
+ if ifyes SURFRAW_pgdoc_comments
+ then
+ inurl="${inurl}interactive/"
+ else
+ inurl="${inurl}static/"
+ fi
+ fi
+ w3_browse_url "http://www.postgresql.org${inurl}"
+
+else
+
+ case "$SURFRAW_pgdoc_version" in
+ all) inurl="-u=docs" ;;
+ *9.3*) inurl="-u=docs -u=9.3" ;;
+ *9.2*) inurl="-u=docs -u=9.2" ;;
+ *9.1*) inurl="-u=docs -u=9.1" ;;
+ *9.0*) inurl="-u=docs -u=9.0" ;;
+ *8.4*) inurl="-u=docs -u=8.4" ;;
+ *) inurl="-u=docs" ;;
+esac
+
+if [ "$SURFRAW_pgdoc_version" != all ]
+then
+ if ifyes SURFRAW_pgdoc_comments
+ then
+ inurl="${inurl} -u=interactive"
+ else
+ inurl="${inurl} -u=static"
+ fi
+fi
+ w3_custom_search -s=www.postgresql.org $inurl "$w3_shquoted_args"
+fi
diff --git a/elvi/phpdoc b/elvi/phpdoc
new file mode 100755
index 0000000..ced083b
--- /dev/null
+++ b/elvi/phpdoc
@@ -0,0 +1,25 @@
+#!/bin/sh
+# ianb at erislabs.net 20130923
+# elvis: phpdoc -- Search php documentation (php.net)
+. surfraw || exit 1
+
+w3_usage_hook () {
+ cat <<EOF
+Usage: $w3_argv0 [search words]...
+Description:
+ Surfraw search php documentation (php.net)
+EOF
+ w3_custom_search_usage
+ w3_global_usage
+}
+
+w3_config
+w3_parse_args "$@"
+if test -z "$w3_args"
+then
+ w3_browse_url "http://www.php.net/docs.php"
+else
+ w3_custom_search -s=php.net "$w3_shquoted_args"
+fi
+
+
diff --git a/elvi/piratebay b/elvi/piratebay
index 49e3731..0afd76a 100755
--- a/elvi/piratebay
+++ b/elvi/piratebay
@@ -1,5 +1,5 @@
#!/bin/sh
-# elvis: piratebay -- Search The Pirate Bay (http://thepiratebay.org)
+# elvis: piratebay -- Search The Pirate Bay (http://thepiratebay.org)
. surfraw || exit 1
diff --git a/elvi/slinuxdoc b/elvi/slinuxdoc
index 51a12f0..50cfe00 100755
--- a/elvi/slinuxdoc
+++ b/elvi/slinuxdoc
@@ -10,6 +10,7 @@ Usage: $w3_argv0 [options] [search words]...
Description:
Surfraw search entries in LDP (www.linuxdoc.org)
EOF
+ w3_custom_search_usage
w3_global_usage
}
@@ -19,6 +20,5 @@ w3_parse_args "$@"
if test -z "$w3_args"; then
w3_browse_url "http://www.tldp.org/"
else
- escaped_args=`w3_url_of_arg $w3_args`
- w3_browse_url "http://www.google.com/search?q=${escaped_args}+site:tldp.org"
+ w3_custom_search -s=tldp.org "$w3_shquoted_args"
fi
diff --git a/elvi/worldwidescience b/elvi/worldwidescience
index ad904ac..76a1bf4 100755
--- a/elvi/worldwidescience
+++ b/elvi/worldwidescience
@@ -1,5 +1,5 @@
#!/bin/sh
-# elvis: worldwidescience -- Search for science with www.worldwidescience.org
+# elvis: worldwidescience -- Search for science with www.worldwidescience.org
. surfraw || exit 1
w3_usage_hook () {
diff --git a/links.IN b/links.IN
index 63083ca..aa7f9f4 100644
--- a/links.IN
+++ b/links.IN
@@ -65,17 +65,21 @@ elvi.1sr.gz @mandir@/man1/l1sp.1sr.gz
elvi.1sr.gz @mandir@/man1/lsm.1sr.gz
elvi.1sr.gz @mandir@/man1/macports.1sr.gz
elvi.1sr.gz @mandir@/man1/mathworld.1sr.gz
+elvi.1sr.gz @mandir@/man1/mdn.1sr.gz
elvi.1sr.gz @mandir@/man1/mininova.1sr.gz
elvi.1sr.gz @mandir@/man1/musicbrainz.1sr.gz
+elvi.1sr.gz @mandir@/man1/mysqldoc.1sr.gz
elvi.1sr.gz @mandir@/man1/netbsd.1sr.gz
elvi.1sr.gz @mandir@/man1/ntrs.1sr.gz
elvi.1sr.gz @mandir@/man1/openbsd.1sr.gz
elvi.1sr.gz @mandir@/man1/openports.1sr.gz
elvi.1sr.gz @mandir@/man1/opensearch.1sr.gz
elvi.1sr.gz @mandir@/man1/pasearch.1sr.gz
+elvi.1sr.gz @mandir@/man1/pgdoc.1sr.gz
+elvi.1sr.gz @mandir@/man1/pgpkeys.1sr.gz
+elvi.1sr.gz @mandir@/man1/phpdoc.1sr.gz
elvi.1sr.gz @mandir@/man1/pin.1sr.gz
elvi.1sr.gz @mandir@/man1/piratebay.1sr.gz
-elvi.1sr.gz @mandir@/man1/pgpkeys.1sr.gz
elvi.1sr.gz @mandir@/man1/priberam.1sr.gz
elvi.1sr.gz @mandir@/man1/pubmed.1sr.gz
elvi.1sr.gz @mandir@/man1/rae.1sr.gz
diff --git a/surfraw.IN b/surfraw.IN
index 048030f..f08429c 100755
--- a/surfraw.IN
+++ b/surfraw.IN
@@ -1,5 +1,4 @@
#!/bin/sh
-# $Id$
# Surfraw -- Shell Users' Revolutionary Front Against the World wide web
#
# Copyright (c) 2003-2010 The Surfraw-Devel Team
@@ -227,7 +226,7 @@ w3_url_escape () {
s/?/%3F/g;
s/@/%40/g;
s/\[/%5B/g;
- s/\\/%74/g;
+ s/\\/%5C/g;
s/\]/%5D/g;
s/\^/%5E/g;
s/{/%7B/g;
@@ -371,6 +370,7 @@ w3_parse_option () {
w3_parse_args () {
w3_args=
+ w3_shquoted_args=
def SURFRAW_browser none
def SURFRAW_browser_args none
defyn SURFRAW_quote_ifs yes
@@ -386,6 +386,12 @@ w3_parse_args () {
fi
if [ $isarg -eq 1 ]
then
+ if [ -z "$w3_shquoted_args" ]
+ then
+ w3_shquoted_args="`quote "$arg"`"
+ else
+ w3_shquoted_args="$w3_shquoted_args `quote "$arg"`"
+ fi
if ok SURFRAW_quote_ifs
then
arg=`quote_ifs "$arg"`
@@ -481,6 +487,68 @@ w3_browse_url () {
fi
}
+w3_custom_search_usage() {
+ echo "Custom search:"
+ echo " To choose which search engine gets used for custom searches,"
+ echo " configure SURFRAW_customsearch_provider"
+ echo " supported: google, duckduckgo, ixquick"
+ echo " default: $SURFRAW_customsearch_provider"
+}
+
+w3_custom_search() {
+ case "$SURFRAW_customsearch_provider" in
+ google) w3_custom_search_google "$@" ;;
+ duckduckgo) w3_custom_search_duckduckgo "$@" ;;
+ ixquick) w3_custom_search_ixquick "$@" ;;
+ *) w3_custom_search_duckduckgo "$@" ;;
+ esac
+}
+
+w3_custom_search_google() {
+ params=$(eval w3_custom_search_mangle -s site: $*)
+ params=$(eval w3_custom_search_mangle -u inurl: $params)
+ params=$(eval w3_custom_search_inurl_quote_dots $params)
+ url="$(eval /usr/bin/surfraw google -p $params )"
+ w3_browse_url "$url"
+}
+
+w3_custom_search_duckduckgo() {
+ params=$(eval w3_custom_search_mangle -s site: $*)
+ params=$(eval w3_custom_search_mangle -u inurl: $params)
+ url="$(eval surfraw duckduckgo -p $params )"
+ w3_browse_url "$url"
+}
+
+w3_custom_search_ixquick() {
+ params=$(eval w3_custom_search_mangle -s host: $*)
+ params=$(eval w3_custom_search_mangle -u url: $params)
+ url="$(eval surfraw ixquick -p $params )"
+ w3_browse_url "$url"
+}
+
+w3_custom_search_mangle() {
+ search="$1"
+ replace="$2"
+ shift
+ shift
+ for arg in "$@"
+ do
+ quote "$(echo "$arg" | sed "s/^${search}=\(.*\)/${replace}\1/")"
+ done
+}
+
+w3_custom_search_inurl_quote_dots() {
+ for arg in "$@"
+ do
+ if echo "$arg" | grep -q -- inurl:
+ then
+ quote "$(echo "$arg" | sed 's/\./\\./g;')"
+ else
+ quote "$arg"
+ fi
+ done
+}
+
quote () {
quoted=`echo "$1"|sed "s/'/'\\\\\''/g"`
echo "'$quoted'"
@@ -548,7 +616,7 @@ then
for arg in "$@"
do
# if it is an option
- if @AWK@ -v arg="$arg" 'BEGIN { if(arg ~ /^-/) { exit 0 } else { exit 1 } } '
+ if [ "$(echo "$arg" | sed 's/^\(.\).*/\1/;' )" = "-" ]
then
# if option before elvi
if [ -z "$elvi" ]
diff --git a/surfraw.conf.IN b/surfraw.conf.IN
index 890b7d4..9eae849 100644
--- a/surfraw.conf.IN
+++ b/surfraw.conf.IN
@@ -86,3 +86,7 @@ defyn SURFRAW_dump no
# Should be a 2-letter iso country code
def SURFRAW_lang ""
+# provider for searches that use a search engine
+# with (eg) site: specifiers
+# supported: google duckduckgo ixquick
+def SURFRAW_customsearch_provider duckduckgo
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/surfraw/surfraw.git
More information about the Surfraw-commits
mailing list