Switch from Unoconv backed to directly use LibreOffice. Unoconv starts
to be buggy and LibreOffice is more tolerant to whether the server is
running, therefore Unoconv is rather in the way.
Use *pdftotext* for conversion of formats that will not convert to
text using LibreOffice (spreadsheets and presentations).
In case chache exists but input filename differ, then rename the
cached filename to match the input one. This is usefull for Mutt,
which always has a different temporary file.
Rename format "pdf" -> "zatura", cfr "emacs"
cache="$HOME/.cache/unoconv-display"
tmp="$XDG_RUNTIME_DIR/${0##*/}"
mkdir -p "$cache" "$tmp"
cache="$HOME/.cache/unoconv-display"
tmp="$XDG_RUNTIME_DIR/${0##*/}"
mkdir -p "$cache" "$tmp"
-if [ "$1" == "-e" ]; then fmt=emacs; shift; else fmt=pdf; fi
debug () {
test -n "$DEBUG" &&\
debug () {
test -n "$DEBUG" &&\
+if [ "$1" == "-e" ]; then fmt=emacs; shift; else fmt=zatura; fi
if [ -n "$1" ]; then file=$1
else file="$tmp/$$"; cat > "$file"; fi
sha=$(sha1sum "$file")
if [ -n "$1" ]; then file=$1
else file="$tmp/$$"; cat > "$file"; fi
sha=$(sha1sum "$file")
debug "Continue for '$fmt', '$tmp', '$file', '$pdf', '$txt'."
debug "Continue for '$fmt', '$tmp', '$file', '$pdf', '$txt'."
-if [ -d "$dir" ]; then # Start text viewer
+if [ -d "$dir" ]; then # rename file to updated filename
+ test -f "$dir"/*.txt && mv -n "$dir"/*.txt "$txt"
+ test $? == 2 && rm -fr "$dir" # some legacy caused duplicates -- start over
+ test -f "$dir"/*.pdf && mv -n "$dir"/*.pdf "$pdf"
+ debug "Cache existed and now renamed."
+fi
+
+if [ -f "$pdf" -a -f "$txt" ]; then # conversion available, start viewer(s)
rm -f "$tmp/$$"
debug "Found '$dir'. Start '$fmt' viewer."
case $fmt in
rm -f "$tmp/$$"
debug "Found '$dir'. Start '$fmt' viewer."
case $fmt in
echo "$txt" 1>&2
exit 0
;;
echo "$txt" 1>&2
exit 0
;;
exec zathura --fork "$pdf" 2>> "/tmp/err" &
echo "$pdf" 1>&2
exit 0
exec zathura --fork "$pdf" 2>> "/tmp/err" &
echo "$pdf" 1>&2
exit 0
-mkdir "$dir"
-unoconv -f pdf -o "$pdf" "$file" || \
- unoconv -l && \
- unoconv -f pdf -o "$pdf" "$file"
-unoconv -f txt -o "$txt" "$file"
+mkdir -p "$dir"
+info "$(libreoffice --convert-to pdf --outdir "$dir" "$file")"
+info "$(libreoffice --convert-to txt --outdir "$dir" "$file")"
+
+if [ -f "$pdf" -a ! -f "$txt" ]; then # failed creating txt with LibreOffice
+ (cd "$dir"; pdftotext "$pdf")
+ info "Created '$txt' with pdftotext."
+fi
+
+if [ ! -f "$pdf" -o ! -f "$txt" ]; then # something went wrong
+ error "Output files are missing"
+fi