commit 66af61d60a30519120199b0c4f01ab33127725b6
parent dfad908d4e64d15222bed8cbc596e07e6f1c929e
Author: Christoph Lohmann <20h@r-36.net>
Date: Fri, 28 Apr 2017 20:40:44 +0200
Add doi: handler.
Diffstat:
2 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/bin/plumber b/bin/plumber
@@ -40,6 +40,7 @@ plumbrules = [
["^dance:.*", "danceopener '%s'"],
["^dict://.*", "dictopener '%s'"],
["^dhl:.*", "dhlopener '%s'"],
+ ["^doi:.*", "doiopener '%s'"],
["^finger://.*", "fingeropener '%s'"],
["^ftp://.*", "ftpopener '%s'"],
["^ftps://.*", "ftpopener '%s'"],
diff --git a/openers/doiopener b/openers/doiopener
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+set -x
+
+if [ $# -lt 1 ];
+then
+ printf "usage: [-o] %s URI\n" "$(basename "$0")" >&2
+ exit 1
+fi
+
+uri="$1"
+doi="$(printf "%s\n" "${uri}" | cut -d':' -f 2-)"
+pdfuri="$(oadoi "${doi}")"
+if [ $? -gt 0 ];
+then
+ plumb "http://doi.org/${doi}"
+else
+ plumb "${pdfuri}"
+fi
+