From adc40a83c45e799b72f997322286bf929c9a3354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9ana=20=E6=B1=9F?= Date: Mon, 14 Jul 2025 14:48:09 +0200 Subject: [PATCH] packages/easyscan: remove temporary pdffiles --- nix/packages/by-name/easyscan/easyscan.sh | 45 +++++++++++++++++++---- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/nix/packages/by-name/easyscan/easyscan.sh b/nix/packages/by-name/easyscan/easyscan.sh index 726ffe78..07536a79 100644 --- a/nix/packages/by-name/easyscan/easyscan.sh +++ b/nix/packages/by-name/easyscan/easyscan.sh @@ -1,18 +1,47 @@ -if [ $# -eq 0 ]; then +# +# Declare variables +# +DEVICE="${SANE_DEFAULT_DEVICE:-}" +OUTPUT_FILE= + +while [[ $# -gt 0 ]]; do + case $1 in + -d | --device) + # Allows user to override the device used, since scanimage is + # slow and the printer might not even change between runs + DEVICE="$2" + shift + shift + ;; + -*) + echo "Unknown option $1" + exit 1 + ;; + *) + OUTPUT_FILE="$1" + shift + ;; + esac +done + +# +# Handle defaults +# +if [ -z "$OUTPUT_FILE" ]; then OUTPUT_FILE=./scan_"$(date)".pdf -else - OUTPUT_FILE="''${1%.*}.pdf" +fi + +if [ -z "$DEVICE" ]; then + DEVICE=$(scanimage --formatted-device-list="%d (%v %m)" --list-devices | + fzf --header "Pick a device:" | + cut -d ' ' -f 1) fi tempdir="$(mktemp -d)" -device=$(scanimage --formatted-device-list="%d (%v %m)" --list-devices | - fzf --header "Pick a device:" | - cut -d ' ' -f 1) - do_scan() { filename="$tempdir/$(date).pdf" - while ! scanimage --format=pdf --device="$device" --resolution 300 >"$filename"; do + while ! scanimage --format=pdf --device="$DEVICE" --resolution 300 >"$filename"; do : done echo "$filename"