commit 26dcd7add009498dcf46725dd5f3e9a5ee748816
parent ef0b2b7c62adf2ac7795e0829ad1a9245f104c10
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Fri, 6 Sep 2019 22:18:54 +0200
Put scholarref tools into separate repository
Diffstat:
3 files changed, 0 insertions(+), 341 deletions(-)
diff --git a/.local/bin/getdoi b/.local/bin/getdoi
@@ -1,141 +0,0 @@
-#!/bin/sh
-
-version=1.0
-host="http://api.crossref.org/works"
-
-show_help() {
- echo "usage: ${0##*/} [OPTIONS] QUERY"
- echo "will attempt to get the DOI from $host"
- echo "where QUERY can consist of publication title, author, DOI, ORCID id,"
- echo "or a PDF file. In case a file is specified, ${0##*/} will attempt to"
- echo "extract the DOI from it."
- echo "If no QUERY is specified, this program will expect a QUERY as stdin."
- echo
- echo "OPTIONS are one or more of the following:"
- echo " -h, --help show this message"
- echo " -v, --version show version and license information"
- echo " -V, --verbose show verbose information"
- echo " -t, --tor-socks use torsocks for HTTP requests"
- echo " -n, --notify send result as desktop notification"
- echo " -N, --number NUM return NUM results (default 1)"
- echo " -c, --clip paste DOI to clipboard (requires xclip)"
- echo " -o, --open open DOI as url in browser"
- echo " -- do not consider any following args as options"
-}
-
-show_version() {
- echo "${0##*/} version $version"
- echo "Licensed under the GNU Public License, v3+"
- echo "written by Anders Damsgaard, anders@adamsgaard.dk"
- echo "https://gitlab.com/admesg/dotfiles"
-}
-
-die() {
- printf '%s\n' "$1" >&2
- exit 1
-}
-
-extract_dois() {
- tr ',' '\n' | grep DOI | \
- sed 's/.*DOI":"//' | sed 's/"}.*//' | sed 's|\\\/|/|g'
-}
-
-browser_open() {
- if command -v xdg-open >/dev/null 2>&1; then
- [ "$verbose" = 1 ] && echo "launching default browser"
- xdg-open "$1"
- elif command -v open >/dev/null 2>&1; then
- [ "$verbose" = 1 ] && echo "launching default browser"
- open "$1"
- else
- die 'Error: could not open a browser'
- fi
-}
-
-get_doi_from_crossref() {
- query="$(echo "$@" | sed 's/ /+/g')"
- url="$host?rows=$number&select=DOI&query=$query"
- [ "$verbose" = 1 ] && echo "connecting to $url"
- result=$($prefix curl --header "Accept: application/json" \
- --header "Content-Type: application/json" \
- --silent --show-error \
- --request GET "$url")
- echo "$result" | extract_dois
-}
-
-get_doi_from_file() {
- doi=$(pdfinfo "$1" | grep -io "doi.*") ||
- doi=$(pdftotext "$1" 2>/dev/null - | grep -io "doi.*" -m 1 ) ||
- die "Error: Could not extract DOI from file $doi"
- doi=$(echo "$doi" | sed 's/[A-Za-z\.\/:]*//;s/[\.,]$//' |\
- sed 's/.*\(10\.\)/\1/' | cut -d' ' -f1 | sed 's/,//g')
- echo "$doi"
-}
-
-get_doi() {
- if [ -e "$1" ]; then
- doi=$(get_doi_from_file "$1")
- else
- doi=$(get_doi_from_crossref "$@")
- fi
- echo "$doi"
- [ "$clip" = 1 ] && echo "https://doi.org/${doi}" | \
- xclip -selection clipboard
- [ "$notify" = 1 ] && notify-send "$doi"
- [ "$open" = 1 ] && browser_open "https://doi.org/${doi}"
-}
-
-verbose=0
-number=1
-clip=0
-open=0
-notify=0
-prefix=""
-while :; do
- case "$1" in
- -h|-\?|--help)
- show_help
- exit 0
- ;;
- -v|--version)
- show_version
- exit 0
- ;;
- -V|--verbose)
- verbose=1
- ;;
- -t|--tor-socks)
- prefix="torsocks"
- ;;
- -N|--number)
- number="$2"
- shift
- ;;
- -n|--notify)
- notify=1
- ;;
- -c|--clip)
- clip=1
- ;;
- -o|--open)
- open=1
- ;;
- --) # end all options
- shift
- break
- ;;
- -?*)
- die 'Error: Unknown option specified'
- ;;
- *) # No more options
- break
- esac
- shift
-done
-
-if [ $# -lt 1 ]; then
- query="$(cat)"
- get_doi "$query"
-else
- get_doi "$@"
-fi
diff --git a/.local/bin/getref b/.local/bin/getref
@@ -1,170 +0,0 @@
-#!/bin/sh
-set -e
-
-version=1.0
-host="https://doi.org"
-
-show_help() {
- echo "usage: ${0##*/} [OPTIONS] DOI1 [DOI2 ...]"
- echo "will attempt to get a BibTeX citation from $host"
- echo "If no DOIs are specified, this program will expect DOIs as stdin."
- echo
- echo "OPTIONS are one or more of the following:"
- echo " -h, --help show this message"
- echo " -v, --version show version and license information"
- echo " -V, --verbose show verbose information"
- echo " -t, --tor-socks use torsocks for HTTP requests"
- echo " -j, --full-journal return full journal name in citation"
- echo " -a, --full-author do not shorten author names"
- echo " -n, --no-newline suppress trailing newline but prepend with newline"
- echo " -N, --notify send desktop notification when complete"
- echo " -- do not consider any following args as options"
-}
-
-show_version() {
- echo "${0##*/} version $version"
- echo "Licensed under the GNU Public License, v3+"
- echo "written by Anders Damsgaard, anders@adamsgaard.dk"
- echo "https://gitlab.com/admesg/dotfiles"
-}
-
-die() {
- printf '%s\n' "$1" >&2
- exit 1
-}
-
-format_bibtex_key() {
- sed '/@/ s/_\([0-9]\)/\1/'
-}
-
-abbreviate_journal_name() {
- sed '/journal = / {
- s/Journal/J./
- s/Geophysical/Geophys./
- s/Research/Res./
- s/Geophysical/Geophys./
- s/Geophysics/Geophys./
- s/Research/Res./
- s/Letters/Lett./
- s/Mechanics/Mech./
- s/Glaciology/Glaciol./
- s/Proceedings/Proc./
- s/Royal/R./
- s/Society/Soc./
- s/Annals/Ann./
- s/Resources/Resour./
- s/Surface/Surf./
- s/Processes/Proc./
- s/National/Nat./
- s/Computers/Comput./
- s/Geotechnics/Geotech./
- s/Academy/Acad./
- s/Sciences/Sci./
- s/Review/Rev./
- s/Quaternary/Quat./
- s/Physical/Phys./
- s/Planetary/Planet./
- s/Quarterly/Q./
- s/Geological/Geol./
- s/Statistical/Stat./
- s/Applied/Appl./
- s/Physics/Phys./
- s/Communications/Commun./
- s/Geoscience/Geosci./
- s/Landforms/Land./
- s/Science/Sci./
- s/Annual/Ann./
- s/International/Int./
- s/Numerical/Numer./
- s/Methods/Meth./
- s/Geomechanics/Geomech./
- s/Analytical/Anal./
- s/ for / /
- s/ of / /
- s/ and / /
- s/ in / /
- }'
-}
-
-abbreviate_author_name() {
- sed '/author = / { s/\([A-Z]\)[A-Za-z]* \([A-Z]\)/\1. \2/g }'
-}
-
-strip_doi() {
- sed 's/^(http:\/\/|https:\/\/)?(dx\.)?(doi\.org\/)//'
-}
-
-get_citation() {
- doi=$(echo "$1" | strip_doi)
- url="$host/$1"
- [ "$verbose" = 1 ] && echo "connecting to $url"
- result=$($prefix curl --location \
- --header "Accept: application/x-bibtex" \
- --silent --show-error "$url")
- echo "$result" | grep -q '<html>' && die 'no result found'
- result="$(echo "$result" | format_bibtex_key)"
- [ "$fulljournal" = 0 ] && result="$(echo "$result" | abbreviate_journal_name)"
- [ "$fullauthor" = 0 ] && result="$(echo "$result" | abbreviate_author_name)"
- result="$(echo "$result" | sed 's/\t/ /g' | grep -v '^ url' )"
- if [ "$nonewline" = 1 ]; then
- printf "\n%s" "$result"
- else
- echo "$result"
- fi
- [ "$notify" = 1 ] && notify-send "${0##*/}" "added: $(echo "$result" | cut -c-80)"
- printf ''
-}
-
-verbose=0
-fulljournal=0
-fullauthor=0
-nonewline=0
-notify=0
-prefix=""
-while :; do
- case "$1" in
- -h|-\?|--help)
- show_help
- exit 0
- ;;
- -v|--version)
- show_version
- exit 0
- ;;
- -j|--full-journal)
- fulljournal=1
- ;;
- -a|--full-author)
- fullauthor=1
- ;;
- -n|--no-newline)
- nonewline=1
- ;;
- -N|--notify)
- notify=1
- ;;
- -V|--verbose)
- verbose=1
- ;;
- -t|--tor-socks)
- prefix="torsocks"
- ;;
- --) # end all options
- shift
- break
- ;;
- -?*)
- die 'Error: Unknown option specified'
- ;;
- *) # No more options
- break
- esac
- shift
-done
-
-if [ $# -lt 1 ]; then
- doi="$(cat)"
- get_citation "$doi"
-else
- get_citation "$@"
-fi
diff --git a/.local/bin/scholarref b/.local/bin/scholarref
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-addref=0
-while :; do
- case "$1" in
- -a|--add)
- addref=1
- ;;
- --) # end all options
- shift
- break
- ;;
- -?*)
- die 'Error: Unknown option specified'
- ;;
- *) # No more options
- break
- esac
- shift
-done
-
-if [ "$addref" = 1 ]; then
- 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"
-else
- getdoi "$@" | getref -n
-fi
-exit 0