+function scan () {
+ n=1
+
+ while [[ -f "${HOME}/scan-${n}.jpg" ]]
+ do
+ n=$((n+1))
+ done
+
+ while [[ "$1" ]]
+ do
+ if [[ "$1" == "color" ]]
+ then
+ OPTS+=" --mode Color"
+ elif [[ "$1" == "gray" ]]
+ then
+ OPTS+=" --mode Gray"
+ elif [[ "$1" == "a4crop" ]]
+ then
+ OPTS+=" -l 5 -t 0 -x 200 -y 300"
+ elif [[ "$1" == "help" ]] || [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]
+ then
+ echo "$0 [color|gray] [a4crop]" && return 0
+ else
+ echo "Unknown argument \`$1'"
+ fi
+ shift
+ done
+
+ echo "**"
+ echo "** Scanning to ${HOME}/scan-${n}.jpg"
+ echo "**"
+
+ SCANNER=$(scanimage -L | grep "Canon LiDE 60" | sed -e "s/^.*\`\(.*\)'.*$/\1/")
+
+ scanimage -d ${SCANNER} \
+ --format=pnm \
+ --mode=color \
+ --depth=8 \
+ -v \
+ --resolution=300 \
+ ${OPTS} | \
+ convert -rotate 180 - "${HOME}/scan-${n}.jpg"
+
+ echo "** Done".
+}
+
+# A password generator
+
+function genpw () {
+ if [[ "$1" == "-e" ]]
+ then
+ PW=$(tr -dc A-Z0-9 < /dev/urandom | head -c6)
+ shift
+ else
+ PW=$(tr -dc A-Za-z0-9 < /dev/urandom | head -c16)
+ fi
+ if [[ ! "$1" == "-s" ]]
+ then
+ echo "$(date) ${PW}" >> ${HOME}/private/genpw.log
+ fi
+ echo ${PW}
+ # tr -dc [:graph:] < /dev/urandom | head -c16
+ echo
+}
+