diff options
author | Ray Patrick <ray@raypatrick.xyz> | 2021-12-30 17:12:19 -0700 |
---|---|---|
committer | Ray Patrick <ray@raypatrick.xyz> | 2021-12-30 17:12:19 -0700 |
commit | 5a60fbe3b2d1f2b1f0947335e015d0a00c73c5f9 (patch) | |
tree | ea2124bc4f4bb7c4d6f12db4f19f1d40eb9d65c3 /bin | |
parent | 8ba5fa8437c6276ba86129dd2237a77e77286d8e (diff) |
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/isbn | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/bin/isbn b/bin/isbn new file mode 100755 index 0000000..a1294fc --- /dev/null +++ b/bin/isbn @@ -0,0 +1,44 @@ +#!/bin/sh + +[ -z $(which jq) ] && printf "isbn: I require jq(1) to work, but I can't find it on your system!\n" && exit + +baseurl=https://www.googleapis.com/books/v1/volumes?q=isbn: + +resultstring=$(curl -s $baseurl$1 | jq -jr '.items[].volumeInfo.authors[], "\t", .items[].volumeInfo.title, "\t", .items[].volumeInfo.publisher, "\t", .items[].volumeInfo.publishedDate' | sed -e 's/\n/\t/g') + +author=$(echo "$resultstring" | cut -f1) +title=$(echo "$resultstring" | cut -f2) +publisher=$(echo "$resultstring" | cut -f3) +year=$(echo "$resultstring" | cut -f4 | head -c4) + +emitbibtex() { +cat << EOF +@book{$(echo "$title" | tr [:upper:] [:lower:] | sed -e 's/ /-/g') +author="$author" +title="$title" +publisher="$publisher" +year="$year" +} +EOF +} + +emitsimple() { +cat << EOF +title: $title +author: $author +publisher: $publisher +date: $(echo "$resultstring" | cut -f4) +EOF +} + +case "$#" in + 0) printf "isbn: no argument specified.\n" & exit ;; + 1) ;; + 2) ;; + *) printf "isbn: too many arguments!\n" & exit ;; +esac + +case "$2" in + -b|--bibtex) emitbibtex ;; + *) emitsimple ;; +esac |