ci: gitify
This commit is contained in:
commit
e7b95801e2
2 changed files with 207 additions and 0 deletions
110
scanmultipage
Executable file
110
scanmultipage
Executable file
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
###
|
||||
: '
|
||||
Scans several pages using `scanpage` and combines them into a single PDF file.
|
||||
'
|
||||
###
|
||||
|
||||
# change this to your preferred PDF viewer
|
||||
_viewer="zathura"
|
||||
|
||||
###
|
||||
|
||||
trap _ctrlc INT
|
||||
|
||||
function _cleanup() {
|
||||
# cleanup _tmpdir
|
||||
rm -rf $_tmpdir
|
||||
}
|
||||
function _ctrlc() {
|
||||
echo "cancelled by SIGINT/^C"
|
||||
_cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
|
||||
_cmd=""
|
||||
_file=""
|
||||
_landscape=false
|
||||
_silent=false
|
||||
_tmpdir=""
|
||||
|
||||
usage () {
|
||||
echo 'Scans several pages using `scanpage` and combines them into a single PDF file.
|
||||
|
||||
options:
|
||||
-h, --help
|
||||
prints this message
|
||||
-l, --landscape
|
||||
rotates the pages 90° left for landscape scans
|
||||
-o, --outfile FILE
|
||||
writes the scan to FILE instead of using a temporary file
|
||||
-r, --rotate
|
||||
same as -l
|
||||
-s, --silent
|
||||
silently write output file, don’t open it
|
||||
--viewer CMD
|
||||
uses CMD as PDF viewer'
|
||||
}
|
||||
|
||||
###~begin option parsing
|
||||
zparseopts -A _OPTS -D -E -- h l o: r --help -outfile: -landscape -rotate -viewer:
|
||||
if [ ! -z "$@" ] ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for opt in "${(@k)_OPTS}"; do
|
||||
case $opt in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-l|-r|--landscape|--rotate)
|
||||
_landscape=true
|
||||
;;
|
||||
-o|--outfile)
|
||||
_file="$_OPTS[$opt]"
|
||||
;;
|
||||
-s|--silent)
|
||||
_silent=true
|
||||
;;
|
||||
--viewer)
|
||||
_viewer="$_OPTS[$opt]"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
###~end option parsing
|
||||
|
||||
# setup temporary directory for scans; we deffo need it for the intermediate,
|
||||
# single page files this time
|
||||
_tmpdir=`mktemp -d`
|
||||
|
||||
# check file ending if outfile is specified (and add it), else use tmpfile
|
||||
if [ ! -z $_file ] ; then
|
||||
if [[ ! "$_file" =~ ".*\.pdf" ]] ; then _file="${_file}.pdf"; fi
|
||||
else
|
||||
_file="${_tmpdir}/$(date +%Y-%m-%d).pdf"
|
||||
fi
|
||||
|
||||
i=1
|
||||
done=false
|
||||
while ! $done
|
||||
do
|
||||
echo "Starting scan …"
|
||||
scanpage -s$( ( $_landscape ) && print "l")o ${_tmpdir}/$(printf "%0*d" 3 ${i}).png
|
||||
echo "Page $i scanned. Insert next page and hit <Enter>. ^D to finish the document."
|
||||
let i++
|
||||
read
|
||||
[ "$?" -eq "1" ] && done=true
|
||||
done
|
||||
|
||||
# concatenate scanned pages
|
||||
echo "Concatenating pages …"
|
||||
convert "$_tmpdir/*.png" $_file
|
||||
|
||||
( $_silent ) || $_viewer $_file >/dev/null 2>/dev/null
|
||||
|
||||
_cleanup
|
97
scanpage
Executable file
97
scanpage
Executable file
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env zsh
|
||||
|
||||
###
|
||||
: '
|
||||
Scans a single page using sane’s `scanimage` and converts it to PDF using
|
||||
ImageMagick’s `convert`.
|
||||
'
|
||||
###
|
||||
|
||||
# find your device URI by doing `lpstat -s`!
|
||||
# (mine is an HP network printer connected through HPLIP)
|
||||
_device="hpaio:/net/DeskJet_3630_series?hostname=drucker.vandenhorz.de"
|
||||
# change this to your preferred PDF viewer
|
||||
_viewer="zathura"
|
||||
|
||||
###
|
||||
|
||||
trap _ctrlc INT
|
||||
|
||||
function _cleanup() {
|
||||
# clean up _tmpdir, if created earlier
|
||||
if [ ! -z $_tmpdir ] ; then rm -rf $_tmpdir; fi
|
||||
}
|
||||
function _ctrlc() {
|
||||
echo "cancelled by SIGINT/^C"
|
||||
_cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
_cmd=""
|
||||
_file=""
|
||||
_landscape=false
|
||||
_silent=false
|
||||
_tmpdir=""
|
||||
|
||||
usage () {
|
||||
echo 'Scans a single page using sane’s `scanimage` and converts it to PDF using ImageMagick’s convert and opens it in Evince.
|
||||
|
||||
options:
|
||||
-h, --help
|
||||
prints this message
|
||||
-l, --landscape
|
||||
rotates the page 90° left for landscape scans
|
||||
-o, --outfile FILE
|
||||
silently writes the scan to FILE instead of using a temporary file
|
||||
implies -s
|
||||
-r, --rotate
|
||||
same as -l
|
||||
-s, --silent
|
||||
silently write output file, don’t open it
|
||||
--viewer CMD
|
||||
uses CMD as PDF viewer instead of Evince'
|
||||
}
|
||||
|
||||
###~begin option parsing
|
||||
zparseopts -A _OPTS -D -E -- h l o: r s -help -outfile: -landscape -rotate -silent -viewer
|
||||
if [ ! -z "$@" ] ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for opt in "${(@k)_OPTS}"; do
|
||||
case $opt in
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-l|-r|--landscape|--rotate)
|
||||
_landscape=true
|
||||
;;
|
||||
-o|--outfile)
|
||||
_file="$_OPTS[$opt]"
|
||||
_silent=true
|
||||
;;
|
||||
-s|--silent)
|
||||
_silent=true
|
||||
;;
|
||||
--viewer)
|
||||
_viewer="$_OPTS[$opt]"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
###~end option parsing
|
||||
|
||||
# check file ending if outfile is specified (and add it), else use tmpfile
|
||||
# skip when silent (e.g. invoked by `scanmultipage`)
|
||||
if [ ! -z $_file ] ; then
|
||||
if [[ ! "$_file" =~ ".*\.pdf" ]] ; then ( $_silent ) || _file="${_file}.pdf"; fi
|
||||
else
|
||||
_tmpdir=`mktemp -d`
|
||||
_file="${_tmpdir}/$(date +%Y-%m-%d).pdf"
|
||||
fi
|
||||
|
||||
scanimage -d "$_device" -p --resolution 300 --mode Color -x 210 -y 297 --format=png | convert $( ( $_landscape ) && print "\-rotate \-90 ")- $_file && \
|
||||
( $_silent ) || $_viewer $_file >/dev/null 2>/dev/null
|
||||
|
||||
_cleanup
|
Loading…
Reference in a new issue