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 "Start"
+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")
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
echo "$txt" 1>&2
exit 0
;;
- pdf)
+ zatura)
exec zathura --fork "$pdf" 2>> "/tmp/err" &
echo "$pdf" 1>&2
exit 0
debug "Convert '$file'."
-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
# Recursively open