From d02c8853b40e612b2045aba612c92d5f89f87e02 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Wed, 14 Dec 2016 11:40:21 -0800 Subject: [PATCH] implement dropbox_read --- dropbox_to_read | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/dropbox_to_read b/dropbox_to_read index 9ca753c..7ea896a 100755 --- a/dropbox_to_read +++ b/dropbox_to_read @@ -1,12 +1,8 @@ #!/bin/bash -set -x -TMPDIR="$(mktemp -d)" - - - -if [ "$0" == "dropbox_to_read" ]; then +if [ "$(basename "$0")" == "dropbox_to_read" ]; then + TMPDIR="$(mktemp -d)" PDF_FILE=$(bibtex_to_paper --only-print "$1") mkdir -p "$TMPDIR/a" mkdir -p "$TMPDIR/b" @@ -16,8 +12,8 @@ if [ "$0" == "dropbox_to_read" ]; then chmod u+w "$TMPDIR/b/file.pdf" qprint -d "${PDF_FILE}.annot" | patch -d "$TMPDIR/b" --binary; else - chmod u+w "$TMPDIR/b/file.pdf" cp "$PDF_FILE" "$TMPDIR/b/file.pdf"; + chmod u+w "$TMPDIR/b/file.pdf" fi; cp "$TMPDIR/b/file.pdf" ~/Dropbox/research_papers/to_read/"$(basename "$PDF_FILE")"; rm -f "$TMPDIR/a/file.pdf" @@ -25,7 +21,28 @@ if [ "$0" == "dropbox_to_read" ]; then rmdir "$TMPDIR/a" "$TMPDIR/b" "$TMPDIR" fi; -if [ "$0" == "dropbox_read" ]; then - echo "Currently not implemented"; - exit 1; +if [ "$(basename "$0")" == "dropbox_read" ]; then + #echo "Currently not implemented"; + # exit 1; + while IFS= read -r -d '' file; do + unset IFS + PDF_FILE="$(bibtex_to_paper --only-print --search-by-file "$(basename "$file")")" + if [ -n "$PDF_FILE" ]; then + ( set -e + TMPDIR="$(mktemp -d)" + mkdir -p "$TMPDIR/a"; + mkdir -p "$TMPDIR/b"; + cp -l "${PDF_FILE}" "$TMPDIR/a/file.pdf"; + chmod u+w "$TMPDIR/a/file.pdf" + cp -l "$file" "$TMPDIR/b/file.pdf"; + echo "${PDF_FILE}.annot"; + (cd "$TMPDIR"; + diff -Nura a b ) | qprint --encode --binary > "${PDF_FILE}.annot" + rm -f "$TMPDIR/a/file.pdf" + rm -f "$TMPDIR/b/file.pdf" + rmdir "$TMPDIR/a" "$TMPDIR/b" "$TMPDIR" + mv "$file" ~/Dropbox/research_papers/annotations_recorded + ); + fi; + done < <(find ~/Dropbox/research_papers/read/ -type f -print0) fi; -- 2.39.2