tDetect DOIs in input - scholarref - tools for DOI and BiBTeX reference extraction, fetching, and parsing
(HTM) git clone git://src.adamsgaard.dk/scholarref
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit ba0f9ec17aeb1c31906ce0fcb206404fe7b60d5d
(DIR) parent 22e5bb6e3edab1cbbf6e557dd1a2f1f94692a99f
(HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Mon, 6 Jul 2020 10:29:56 +0200
Detect DOIs in input
Diffstat:
M scholarref | 32 ++++++++++++++++++++++++-------
1 file changed, 25 insertions(+), 7 deletions(-)
---
(DIR) diff --git a/scholarref b/scholarref
t@@ -16,7 +16,7 @@ while :; do
break
;;
-?*)
- die 'Error: Unknown option specified'
+ die 'error: unknown option specified'
;;
*) # No more options
break
t@@ -24,12 +24,30 @@ while :; do
shift
done
+regexmatch() {
+ printf '%s' "$1" | grep -qE "$2"
+}
+
+get_reference() {
+ if regexmatch "$1" '^(doi:[/]*|https*://(dx\.)*doi.org/)*10\.[0-9\.]+/'; then
+ getref -n "10${1#*10}"
+ else
+ getdoi "$@" | getref -n
+ fi
+}
+
if [ "$addref" = 1 ]; then
- [ -z "$BIB" ] && die 'BIB env variable not set, should point to .bib file'
- getdoi "$@" | getref -n >> "$BIB"
- key="$(grep '@.*{' "$BIB" | tail -n 1 | sed 's/.*{//;s/,$//')"
- echo "Citation $key added to $BIB"
- notify-send "${0##/*} Citation $key added"
+ if [ -z "$BIB" ]; then
+ die 'BIB env variable not set, should point to .bib file'
+ fi
+ get_reference "$@" >> "$BIB"
+ if [ "$?" -eq 0 ]; then
+ key="$(grep '@.*{' "$BIB" | tail -n 1 | sed 's/.*{//;s/,$//')"
+ echo "Citation $key added to $BIB"
+ notify-send "${0##/*} Citation $key added"
+ else
+ die 'could not find reference'
+ fi
else
- getdoi "$@" | getref -n
+ get_reference "$@"
fi