mirror of
https://github.com/rocketraman/sane-scan-pdf.git
synced 2025-05-16 23:50:39 -07:00
Support named option groups
This commit is contained in:
parent
eea2c495d9
commit
fe85eff576
50
scan
50
scan
@ -35,6 +35,7 @@ WHITE_THRESHOLD=99.8
|
|||||||
BRIGHTNESS_CONTRAST=
|
BRIGHTNESS_CONTRAST=
|
||||||
SOURCE=""
|
SOURCE=""
|
||||||
OPENSCAN=0
|
OPENSCAN=0
|
||||||
|
OPTION_GROUP=""
|
||||||
|
|
||||||
TMP_DIR=$(mktemp -d -p "" scan.XXXXXXXXXX)
|
TMP_DIR=$(mktemp -d -p "" scan.XXXXXXXXXX)
|
||||||
cleanup()
|
cleanup()
|
||||||
@ -48,7 +49,35 @@ SCANPRE="${XDG_DATA_HOME:-$HOME/.local/share}/sane-scan-pdf/scan_pre"
|
|||||||
|
|
||||||
[ -e "$DEFAULTS" ] && . "$DEFAULTS"
|
[ -e "$DEFAULTS" ] && . "$DEFAULTS"
|
||||||
|
|
||||||
# Parse command-line options
|
# copy the args
|
||||||
|
args=("$@")
|
||||||
|
|
||||||
|
# Parse command-line options that change how settings are read first
|
||||||
|
# This way, things like preset option groups can be set first, then overwritten by explicit args
|
||||||
|
while [[ $# > 0 ]]; do
|
||||||
|
case "$1" in
|
||||||
|
|
||||||
|
-h|--help) HELP=1 ;;
|
||||||
|
|
||||||
|
-og|--option-group) shift; OPTION_GROUP="${XDG_DATA_HOME:-$HOME/.local/share}/sane-scan-pdf/$1" ;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
shift # next option
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -f "$OPTION_GROUP" ]]; then
|
||||||
|
. "$OPTION_GROUP"
|
||||||
|
elif [[ "$OPTION_GROUP" != "" && $HELP == 0 ]]; then
|
||||||
|
echo "2"
|
||||||
|
echo >&2 "Warning: '--option-group' specified, but the corresponding file $OPTION_GROUP does not exist."
|
||||||
|
else
|
||||||
|
echo "3"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# reset the args
|
||||||
|
set -- "${args[@]}"
|
||||||
|
|
||||||
|
# Parse other command-line options, these will now overwrite anything set via defaults or option groups
|
||||||
while [[ $# > 0 ]]; do
|
while [[ $# > 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
||||||
@ -68,7 +97,8 @@ while [[ $# > 0 ]]; do
|
|||||||
|
|
||||||
-t|--truncate) shift; TRUNCPAGE=$1 ;;
|
-t|--truncate) shift; TRUNCPAGE=$1 ;;
|
||||||
|
|
||||||
-h|--help) HELP=1 ;;
|
# ignore, already handled
|
||||||
|
-h|--help) shift ;;
|
||||||
|
|
||||||
-s|--size) shift; SIZE=$1 ;;
|
-s|--size) shift; SIZE=$1 ;;
|
||||||
|
|
||||||
@ -104,6 +134,9 @@ while [[ $# > 0 ]]; do
|
|||||||
|
|
||||||
--open) OPENSCAN=1 ;;
|
--open) OPENSCAN=1 ;;
|
||||||
|
|
||||||
|
# ignore, already handled
|
||||||
|
-og|--option-group) shift ;;
|
||||||
|
|
||||||
*) if [[ $USEARRAY == 1 ]]; then OUTPUTARR+=("$1"); else echo >&2 "Unknown argument: $1"; exit 1; fi ;;
|
*) if [[ $USEARRAY == 1 ]]; then OUTPUTARR+=("$1"); else echo >&2 "Unknown argument: $1"; exit 1; fi ;;
|
||||||
|
|
||||||
esac
|
esac
|
||||||
@ -162,6 +195,9 @@ if [[ $HELP == 1 ]]; then
|
|||||||
echo " contrast via --driver-options if supported by your hardware."
|
echo " contrast via --driver-options if supported by your hardware."
|
||||||
echo " --open"
|
echo " --open"
|
||||||
echo " After scanning, open the scan via xdg-open"
|
echo " After scanning, open the scan via xdg-open"
|
||||||
|
echo " -og, --option-group"
|
||||||
|
echo " A named option group. Useful for saving collections of options under a name e.g. 'receipt' for easy reuse."
|
||||||
|
echo " Use this option in combination with '--help' to show the location and content of the file and edit it manually."
|
||||||
echo ""
|
echo ""
|
||||||
echo "OUTPUT"
|
echo "OUTPUT"
|
||||||
echo " -o, --output <outputfile>"
|
echo " -o, --output <outputfile>"
|
||||||
@ -179,6 +215,16 @@ if [[ $HELP == 1 ]]; then
|
|||||||
echo "-----"
|
echo "-----"
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
|
echo "A named option group can be written based on the '--option-group' argument. Current:"
|
||||||
|
echo " $OPTION_GROUP"
|
||||||
|
if [[ -e "$OPTION_GROUP" ]]; then
|
||||||
|
echo ""
|
||||||
|
echo "This file exists and currently contains:"
|
||||||
|
echo "-----"
|
||||||
|
cat "$OPTION_GROUP"
|
||||||
|
echo "-----"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
echo "A pre-scan hook script can be written to:"
|
echo "A pre-scan hook script can be written to:"
|
||||||
echo " $SCANPRE"
|
echo " $SCANPRE"
|
||||||
if [[ -e "$SCANPRE" ]]; then
|
if [[ -e "$SCANPRE" ]]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user