#!/bin/bash this="${0##*/}" diff=$(which puzzle-diff) function usage() { printf "Usage: $this IMAGE [DIRECTORIES]\n" printf "Find images in DIRECTORIES that are similar to IMAGE.\n\n" printf "If a DIRECTORIES is omitted ~/img/chan/ is used by default\n" exit 100 } if [ ${#@} -eq 0 ] ; then usage fi declare -a dirs reference="$1" shift if [ ${#@} -gt 0 ] ; then dirs=("$@") else dirs=(~/img/chan/) fi if [ ! -f "$reference" ] ; then printf "$this: '$reference' does not exist or is not a regular file\n" usage fi # include here a check for image types # what formats does puzzle-diff support? if [ ! -x "$diff" ] ; then printf "$this requires puzzle-diff, but it was not found in your PATH\n" exit 101 fi find \ "${dirs[@]}" -type f -not -path '*/x/*' \ \( \ -iname '*.jpg' \ -o \ -iname '*.png' \ -o \ -iname '*.jpeg' \ \) \ -printf "%p: " \ -exec bash -c \ 'R=$('"$diff"' "'$reference'" "$1") ; echo $R ' -- {} \ \; \ | sort -r -n -t : -k 2