X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=evince_annot;h=8c66a1829362f7983b7baf3e151944b950097660;hb=dcce90e77c92202b5fadca48de6fd1cefc41ff79;hp=1a9c1e329ac63904433fb96bd787a88694694631;hpb=e88885b27f22602722e9087b31c073a64f0b06ca;p=bin.git diff --git a/evince_annot b/evince_annot index 1a9c1e3..8c66a18 100755 --- a/evince_annot +++ b/evince_annot @@ -4,28 +4,41 @@ set -x TMPDIR="$(mktemp -d)" -mkdir -p "$TMPDIR/a" -mkdir -p "$TMPDIR/b" -cp -l "$1" "$TMPDIR/a/file.pdf"; -if [ -e "${1}.annot" ]; then - cp "$1" "$TMPDIR/b/file.pdf"; +mkdir -p "$TMPDIR/a" "$TMPDIR/b" "$TMPDIR/c" +PDF_FILE="$(realpath "$1")" +ANNOT_FILE="$(realpath "${1}.annot")" +cp -l "$PDF_FILE" "$TMPDIR/a/file.pdf"; +if [ -e "$ANNOT_FILE" ]; then + cp "$PDF_FILE" "$TMPDIR/b/file.pdf"; chmod u+w "$TMPDIR/b/file.pdf" - qprint -d "${1}.annot" | patch -d "$TMPDIR/b" --binary; + qprint --binary --decode "$ANNOT_FILE" | patch -d "$TMPDIR/b" --binary; + cp "$TMPDIR/b/file.pdf" "$TMPDIR/c/file.pdf"; else + cp "$PDF_FILE" "$TMPDIR/b/file.pdf"; + cp "$PDF_FILE" "$TMPDIR/c/file.pdf"; chmod u+w "$TMPDIR/b/file.pdf" - cp "$1" "$TMPDIR/b/file.pdf"; fi; (cd "$TMPDIR/b" chmod u+w "file.pdf" - ## evince really should just use the same document-directory - gsettings set org.gnome.Evince document-directory "'file://$TMPDIR/b'"; - evince "file.pdf" + if which okular > /dev/null 2>&1; then + okular "file.pdf" + else + ## evince really should just use the same document-directory + gsettings set org.gnome.Evince document-directory "'file://$TMPDIR/b'"; + evince "file.pdf" + fi; ); -(cd "$TMPDIR"; - diff -Nura a b ) | qprint -e > "${1}.annot" +if ! cmp "$TMPDIR/b/file.pdf" "$TMPDIR/c/file.pdf"; then + (cd "$TMPDIR"; + diff -Nura a b ) | qprint --encode --binary > "$ANNOT_FILE" +fi; +if ! [ -s "$ANNOT_FILE" ]; then + rm -f "$ANNOT_FILE"; +fi; rm -f "$TMPDIR/a/file.pdf" rm -f "$TMPDIR/b/file.pdf" -rmdir "$TMPDIR/a" "$TMPDIR/b" "$TMPDIR" +rm -f "$TMPDIR/c/file.pdf" +rmdir "$TMPDIR/a" "$TMPDIR/b" "$TMPDIR/c" "$TMPDIR"