summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xopen-as-pdf19
1 files changed, 13 insertions, 6 deletions
diff --git a/open-as-pdf b/open-as-pdf
index cc96c09..8d09ad2 100755
--- a/open-as-pdf
+++ b/open-as-pdf
@@ -1,10 +1,17 @@
-#!/bin/sh
+#!/usr/bin/env bash
-if [ $# -eq 0 ] ; then
+set -euo pipefail
+
+main() {
+ if [ $# -eq 0 ]; then
echo First arguments must be a file.
exit 1
-fi
+ fi
+
+ OUTPUT_DIR=$(mktemp --directory)
+ trap 'rm -rf "$OUTPUT_DIR"' EXIT
+
+ soffice --convert-to pdf --outdir "$OUTPUT_DIR" "$1" && xdg-open "$OUTPUT_DIR"/*.pdf && sleep 5
+}
-PDF_FILE="$(tempfile --suffix .pdf)"
-trap 'rm "$PDF_FILE"' EXIT
-unoconv --format pdf -o "$PDF_FILE" "$1" && xdg-open "$PDF_FILE" && sleep 5
+main "$@"