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"