]> git.donarmstrong.com Git - bin.git/blobdiff - dropbox_to_read
add git-hogs command
[bin.git] / dropbox_to_read
index 9ca753cfd641e798bd3b405669b8d15c0110bca3..a6ed7c9bea5e77ce9547f1ac3e8e6f72d586e527 100755 (executable)
@@ -1,31 +1,54 @@
 #!/bin/bash
 
 
-set -x 
-TMPDIR="$(mktemp -d)"
-
-
-
-if [ "$0" == "dropbox_to_read" ]; then
-    PDF_FILE=$(bibtex_to_paper --only-print "$1")
-    mkdir -p "$TMPDIR/a"
-    mkdir -p "$TMPDIR/b"
-    cp -l "$PDF_FILE" "$TMPDIR/a/file.pdf";
-    if [ -e "${PDF_FILE}.annot" ]; then
-        cp "$PDF_FILE" "$TMPDIR/b/file.pdf";
-        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";
-    fi;
-    cp "$TMPDIR/b/file.pdf" ~/Dropbox/research_papers/to_read/"$(basename "$PDF_FILE")";
-    rm -f "$TMPDIR/a/file.pdf"
-    rm -f "$TMPDIR/b/file.pdf"
-    rmdir "$TMPDIR/a" "$TMPDIR/b" "$TMPDIR"
+if [ "$(basename "$0")" == "dropbox_to_read" ]; then
+    for a in "$@"; do
+        LOCTMPDIR="$(mktemp -d)"
+        PDF_FILE=$(bibtex_to_paper --only-print "$a")
+        mkdir -p "$LOCTMPDIR/a"
+        mkdir -p "$LOCTMPDIR/b"
+        cp -l "$PDF_FILE" "$LOCTMPDIR/a/file.pdf";
+        if [ -e "${PDF_FILE}.annot" ]; then
+            cp "$PDF_FILE" "$LOCTMPDIR/b/file.pdf";
+            chmod u+w "$LOCTMPDIR/b/file.pdf"
+            qprint -d "${PDF_FILE}.annot" | patch -d "$LOCTMPDIR/b" --binary;
+        else
+            cp "$PDF_FILE" "$LOCTMPDIR/b/file.pdf";
+            chmod u+w "$LOCTMPDIR/b/file.pdf"
+        fi;
+        cp "$LOCTMPDIR/b/file.pdf" ~/Dropbox/research_papers/to_read/"$(basename "$PDF_FILE")";
+        rm -f "$LOCTMPDIR/a/file.pdf"
+        rm -f "$LOCTMPDIR/b/file.pdf"
+        rmdir "$LOCTMPDIR/a" "$LOCTMPDIR/b" "$LOCTMPDIR"
+    done;
 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
+              LOCTMPDIR="$(mktemp -d)"
+              mkdir -p "$LOCTMPDIR/a";
+              mkdir -p "$LOCTMPDIR/b";
+              cp -l "${PDF_FILE}" "$LOCTMPDIR/a/file.pdf";
+              chmod u+w "$LOCTMPDIR/a/file.pdf"
+              cp -l "$file" "$LOCTMPDIR/b/file.pdf";
+              echo "${PDF_FILE}.annot";
+              (cd "$LOCTMPDIR";
+               diff -Nura a b ) | qprint --encode --binary > "${PDF_FILE}.annot"
+              # delete the annot file if it has size 0
+              if ! [ -s "${PDF_FILE}.annot" ]; then
+                  rm -f "${PDF_FILE}.annot"
+              fi;
+              rm -f "$LOCTMPDIR/a/file.pdf"
+              rm -f "$LOCTMPDIR/b/file.pdf"
+              rmdir "$LOCTMPDIR/a" "$LOCTMPDIR/b" "$LOCTMPDIR"
+              mv "$file" ~/Dropbox/research_papers/annotations_recorded
+            );
+        fi;
+    done < <(find ~/Dropbox/research_papers/read/ -type f -print0)
 fi;