diff --git a/nix/packages/by-name/easyscan/easyscan.sh b/nix/packages/by-name/easyscan/easyscan.sh old mode 100644 new mode 100755 index 633c7686..c60430f2 --- a/nix/packages/by-name/easyscan/easyscan.sh +++ b/nix/packages/by-name/easyscan/easyscan.sh @@ -1,11 +1,51 @@ +#!/usr/bin/env bash # This is here because scanimage's batch mode is broken for my scanner -OUTPUT_FILE="${1:-./scan_"$(date)".pdf}" +function help() { + cat < [ -- args ]: + Scan a (multi-page) document to , passing args to scanimage +EOF +} + +if [ $# -lt 1 ]; then + help + exit 1 +fi +OUTPUT_FILE="$1.pdf" if [ -e "$OUTPUT_FILE" ]; then echo "$OUTPUT_FILE" already exists, you are probably making a mistake! exit 1 fi +shift + +scanimage_args=( + "-x" "210" + "-y" "297" + "--resolution" "300" +) + +while [ $# -gt 0 ]; do + case $1 in + --help) + help + exit + ;; + --) + shift + scanimage_args+=("$@") + break + ;; + *) + shift + ;; + esac +done tempdir="$(mktemp -d)" filenames=() @@ -26,11 +66,7 @@ while :; do # If no size is set, the output will be wonky-sized # 210,297 is the size of A4 - scanimage -x 210 -y 297 --resolution 300 -o "$CUR_FNAME" >/dev/null 2>&1 || - { - echo "Failed to scan page..." - ok="false" - } + scanimage "${scanimage_args[@]}" -o "$CUR_FNAME" || ok="false" if $ok; then counter=$((counter += 1))