]> git.donarmstrong.com Git - bin.git/blob - syncthing_to_read
add reset usb bus command
[bin.git] / syncthing_to_read
1 #!/bin/bash
2
3
4 if [ "$(basename "$0")" == "syncthing_to_read" ]; then
5     for a in "$@"; do
6         LOCTMPDIR="$(mktemp -d)"
7         PDF_FILE=$(bibtex_to_paper --only-print "$a")
8         mkdir -p "$LOCTMPDIR/a"
9         mkdir -p "$LOCTMPDIR/b"
10         cp -l "$PDF_FILE" "$LOCTMPDIR/a/file.pdf";
11         if [ -e "${PDF_FILE}.annot" ]; then
12             cp "$PDF_FILE" "$LOCTMPDIR/b/file.pdf";
13             chmod u+w "$LOCTMPDIR/b/file.pdf"
14             qprint -d "${PDF_FILE}.annot" | patch -d "$LOCTMPDIR/b" --binary;
15         else
16             cp "$PDF_FILE" "$LOCTMPDIR/b/file.pdf";
17             chmod u+w "$LOCTMPDIR/b/file.pdf"
18         fi;
19         cp "$LOCTMPDIR/b/file.pdf" ~/Sync/research_papers/to_read/"$(basename "$PDF_FILE")";
20         rm -f "$LOCTMPDIR/a/file.pdf"
21         rm -f "$LOCTMPDIR/b/file.pdf"
22         rmdir "$LOCTMPDIR/a" "$LOCTMPDIR/b" "$LOCTMPDIR"
23     done;
24 fi;
25
26 if [ "$(basename "$0")" == "syncthing_read" ]; then
27     #echo "Currently not implemented";
28     # exit 1;
29     while IFS= read -r -d '' file; do
30         unset IFS
31         PDF_FILE="$(bibtex_to_paper --only-print --search-by-file "$(basename "$file")")"
32         if [ -n "$PDF_FILE" ]; then
33             ( set -e
34               LOCTMPDIR="$(mktemp -d)"
35               mkdir -p "$LOCTMPDIR/a";
36               mkdir -p "$LOCTMPDIR/b";
37               cp -l "${PDF_FILE}" "$LOCTMPDIR/a/file.pdf";
38               chmod u+w "$LOCTMPDIR/a/file.pdf"
39               cp -l "$file" "$LOCTMPDIR/b/file.pdf";
40               echo "${PDF_FILE}.annot";
41               (cd "$LOCTMPDIR";
42                diff -Nura a b ) | qprint --encode --binary > "${PDF_FILE}.annot"
43               # delete the annot file if it has size 0
44               if ! [ -s "${PDF_FILE}.annot" ]; then
45                   rm -f "${PDF_FILE}.annot"
46               fi;
47               rm -f "$LOCTMPDIR/a/file.pdf"
48               rm -f "$LOCTMPDIR/b/file.pdf"
49               rmdir "$LOCTMPDIR/a" "$LOCTMPDIR/b" "$LOCTMPDIR"
50               mv "$file" ~/Sync/research_papers/annotations_recorded
51             );
52         fi;
53     done < <(find ~/Sync/research_papers/read/ -type f -print0)
54 fi;