dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit fa0603a5aca02ab8cd255741805c9bcd6bd301c8
parent 0796d2904899666baa3a94d7abd4c20233bee56c
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed, 10 Apr 2019 13:44:38 +0200

Add ssh configuration and citation tools

Diffstat:
A.ssh/config | 30++++++++++++++++++++++++++++++
Abin/getcitation | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/scholarref | 3+++
3 files changed, 172 insertions(+), 0 deletions(-)

diff --git a/.ssh/config b/.ssh/config @@ -0,0 +1,30 @@ +AddKeysToAgent yes + +Host * + ForwardX11Trusted no + ForwardX11 no + +Host home + Hostname 85.191.223.149 + User ad + Port 12344 + +Host ad-server + Hostname 192.168.0.57 + User ad + Port 12344 + +Host ad-server-wifi + Hostname 192.168.0.45 + User ad + Port 12344 + +Host adamsgaard.dk + Hostname adamsgaard.dk + User ad + Port 12344 + +Host debvm + Hostname adamsgaard.dk + User ad + Port 12346 diff --git a/bin/getcitation b/bin/getcitation @@ -0,0 +1,139 @@ +#!/usr/bin/env bash + +version=1.0 +host="https://doi.org" + +function 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 " -- do not consider any following args as options" +} + +function 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" +} + +function die { + printf '%s\n' "$1" >&2 + exit 1 +} + +function format_bibtex_key { + sed '/@/ s/_\([0-9]\)/\1/' +} + +function 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/Applied/Appl./ + s/Physics/Phys./ + s/Communications/Commun./ + s/Geoscience/Geosci./ + s/Landforms/Land./ + }' +} + +function abbreviate_author_name { + sed '/author = / { s/\([A-Z]\)[A-Za-z]* \([A-Z]\)/\1. \2/g }' +} + +function strip_doi { + sed 's/^(http:\/\/|https:\/\/)?(dx\.)?(doi\.org\/)//' +} + +function 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") + result="$(echo "$result" | format_bibtex_key)" + [ "$fulljournal" = 0 ] && result="$(echo "$result" | abbreviate_journal_name)" + [ "$fullauthor" = 0 ] && result="$(echo "$result" | abbreviate_author_name)" + echo "$result" +} + +verbose=0 +fulljournal=0 +fullauthor=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 + ;; + -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/bin/scholarref b/bin/scholarref @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -e +getdoi "$@" | getcitation