[Surfraw-devel] [PATCH] new elvi: commandlinefu
l-m-h at web.de
l-m-h at web.de
Sat Sep 20 22:07:12 UTC 2014
From: Lucas Hoffmann <l-m-h at web.de>
---
AUTHORS | 5 +++-
ChangeLog | 6 ++++-
README | 1 +
elvi/Makefile.am | 1 +
elvi/commandlinefu | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
links.IN | 1 +
test/commandlinefu.test | 10 ++++++++
7 files changed, 87 insertions(+), 2 deletions(-)
create mode 100755 elvi/commandlinefu
create mode 100644 test/commandlinefu.test
diff --git a/AUTHORS b/AUTHORS
index fa2027c..bd8cdcc 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -133,7 +133,7 @@ Paulo Almeida <paulo at diasalmeida.com>
elvi: priberam
Shain Singh <shain.singh at gmail.com>
- elvi: cisco, f5
+ elvi: cisco, f5
Manolo Martínez <manolo at austrohungaro.com>
examples: elinks integration (hooks.lua)
@@ -141,6 +141,9 @@ Manolo Martínez <manolo at austrohungaro.com>
Jon Yamokoski <jon at jonyamo.net>
elvi: phpdoc
+Lucas Hoffmann <l-m-h at web.de>
+ elvi: commandlinefu
+
THANKS TO
Brian Nelson <bnelson at bloodclot.net>
diff --git a/ChangeLog b/ChangeLog
index 9dc59cb..c52b9e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
+2014-09-20 Lucas Hoffmann <l-m-h at web.de>
+
+ * new elvi: commandlinefu
+
2104-06-04 Jason Ryan <jasonwryan at gmail.com>
-
+
* new elvi: nlab
2013-12-10 Ian Beckwith <ianb at erislabs.net>
diff --git a/README b/README
index ecb9f3f..ac4f0bc 100644
--- a/README
+++ b/README
@@ -196,6 +196,7 @@ cite -- Search computer science papers (citeseerx.ist.psu.edu)
cliki -- Search the common lisp wiki
cnn -- Search on CNN (cnn.com)
comlaw -- Search Australian Law using Comlaw (www.comlaw.gov.au)
+commandlinefu -- Search on www.commandlinefu.com
ctan -- Search the Comprehensive TeX Archive Network (ctan.org)
currency -- Convert currencies with the Universal Currency Converter (www.xe.net/ucc)
cve -- Search for CAN assignments in CVE
diff --git a/elvi/Makefile.am b/elvi/Makefile.am
index b0345bc..6dec47e 100644
--- a/elvi/Makefile.am
+++ b/elvi/Makefile.am
@@ -26,6 +26,7 @@ dist_elvi_SCRIPTS = \
cliki \
cnn \
comlaw \
+ commandlinefu \
ctan \
currency \
cve \
diff --git a/elvi/commandlinefu b/elvi/commandlinefu
new file mode 100755
index 0000000..d3de574
--- /dev/null
+++ b/elvi/commandlinefu
@@ -0,0 +1,65 @@
+#!/bin/sh
+# $Id$
+# elvis: commandlinefu -- search on www.commandlinefu.com
+# The API of the site is described at http://www.commandlinefu.com/site/api.
+. surfraw || exit 1
+
+w3_config_hook () {
+ defyn SURFRAW_commandlinefu_votes 1
+ def SURFRAW_commandlinefu_format html
+}
+
+w3_usage_hook () {
+ cat <<EOF
+Usage: $w3_argv0 [options] [search words]...
+Description:
+ Surfraw search www.commandlinefu.com
+Local options:
+ -html get results as html
+ -txt get results as plain text
+ -json get results as json
+ -rss get results as rss data
+ Default: $SURFRAW_commandlinefu_format
+ -v, -s, -votes, -sort sort results by votes
+ -u, -n, -unsort, -nosort do not sort results
+ Default: $SURFRAW_commandlinefu_votes
+EOF
+ w3_global_usage
+}
+
+w3_parse_option_hook () {
+ opt="$1"
+ optarg="$2"
+ case "$opt" in
+ -json) setopt SURFRAW_commandlinefu_format json ;;
+ -html) setopt SURFRAW_commandlinefu_format html ;;
+ -rss) setopt SURFRAW_commandlinefu_format rss ;;
+ -txt) setopt SURFRAW_commandlinefu_format plaintext ;;
+ -v|-votes|-s|-sort) setoptyn SURFRAW_commandlinefu_votes 1 ;;
+ -u|-unsort|-n|-nosort) setoptyn SURFRAW_commandlinefu_votes 0 ;;
+ *) return 1 ;;
+ esac
+ return 0
+}
+
+w3_config
+w3_parse_args "$@"
+# w3_args now contains a list of arguments
+
+url=http://www.commandlinefu.com/commands/matching
+# The next part of the url is a normalized plaintext version of the search
+# query. It seems to be unused by the CGI but it needs to be present. So we
+# normalize to "x".
+url=$url/x
+# What is really used is the base64 encoded query. (echo -n is not portable)
+url=$url/"`printf %s "$w3_args" | base64`"
+# possibly add the sorting option
+if test $SURFRAW_commandlinefu_votes -eq 1; then
+ url="$url/sort-by-votes"
+fi
+# add the output format option
+if test $SURFRAW_commandlinefu_format != html; then
+ url="$url/$SURFRAW_commandlinefu_format"
+fi
+
+w3_browse_url "$url"
diff --git a/links.IN b/links.IN
index 9fc4dc3..80db370 100644
--- a/links.IN
+++ b/links.IN
@@ -21,6 +21,7 @@ elvi.1sr.gz @mandir@/man1/cia.1sr.gz
elvi.1sr.gz @mandir@/man1/cliki.1sr.gz
elvi.1sr.gz @mandir@/man1/cnn.1sr.gz
elvi.1sr.gz @mandir@/man1/comlaw.1sr.gz
+elvi.1sr.gz @mandir@/man1/commandlinefu.1sr.gz
elvi.1sr.gz @mandir@/man1/ctan.1sr.gz
elvi.1sr.gz @mandir@/man1/currency.1sr.gz
elvi.1sr.gz @mandir@/man1/cve.1sr.gz
diff --git a/test/commandlinefu.test b/test/commandlinefu.test
new file mode 100644
index 0000000..a5dc9c7
--- /dev/null
+++ b/test/commandlinefu.test
@@ -0,0 +1,10 @@
+commandlinefu
+is the place to record those command-line gems that you return to again and again
+commandlinefu find something
+Terminal - Commands matching find something - [\d,]+ results
+commandlinefu -txt test
+^# commandlinefu.com by David Winterbottom\n
+commandlinefu -json test
+^\[\{"id":"\d+","command":.*\}\]$
+commandlinefu -rss test
+</rss>
--
2.1.0
More information about the Surfraw-devel
mailing list