Plaster
New
List
Login
text
default
isoraqathedh
2022.05.04 14:23:28
#!/bin/zsh cd ~/Documents/My\ Scans/Book\ of\ Conworlds progname=${0##*/} help () { cat <<EOF usage: ${progname} [-h] [-f] [-p FMT] [OPTION-NAME VALUE]... Find Book of Conworlds files that match the specified criteria, expressed in key-value pairs. Optionally, open the found files in Feh. -f Open the list of files in Feh -h Open this help -p Format the output using exiftool's -p option -d Open feh but finish when it is open. -i interactive: Certain older folders are not converted to the new format or are missing some values; these are not detected by this program. Available OPTION-NAMEs: book VALUE is a number that indicates the book number. It is possible to specify the series by utilising the series' format, i.e. a plain number for BOC pages, a plain number prefixed with a p for Purple pages, and a plain letter for annexes. series VALUE is one of boc, purple or annex, which forces the selection. page Ditto, for page. subpage Ditto, for a letter with the subpage number. title VALUE is part of the title. Case insensitive. tag VALUE is a tag name. since VALUE is a date, yyyy:mm:dd, that says the time is created then. Includes the date. before As since but specifies an end date. Does not include the date. EOF } output="\$Directory/\$Filename" while getopts :fhp:di OPT; do case $OPT in f|+f) fehp=feh ;; h|+h) help exit 0;; p|+p) if [[ -n $OPTARG ]];then output="\$Filename: $OPTARG" fi;; d|+d) fehp=feh daemon=1;; *) help exit 2 esac done shift OPTIND-1 OPTIND=1 search_tags=$@ expr="" series="" while [[ -n $1 ]]; do if [[ -z $2 ]]; then pst -e Argument for $1 not found. exit 1; fi case $1 in series) series="$2";; book) book="$2";; page) page="$2";; subpage) subpage="$2";; title) expr+=" && \$Title =~ /$2/i";; tags|tag) expr+=" && \$Subject =~ /$2/i";; since) expr+=" && \$createdate ge '$2'";; before) expr+=" && \$createdate lt '$2'";; during) expr+=" && \$createdate =~ /$2/";; *) pst -e The option $1 is not found. help exit 1;; esac shift 2 done # Explicit series calculation case $series in boc) prefix="Book ";; annex) prefix="Annex ";; purple) prefix="Book p";; "") # Implicit series calculation case $book in p[0-9]*) prefix="Book ";; [0-9]*) prefix="Book ";; [a-z]*) prefix="Annex ";; "") :;; *) pst -e Pattern specified by $book does not match any known series. exit 3;; esac;; *) pst -e The series $series is not defined. exit 3;; esac # Set up the remaining arguments [[ -n $prefix || -n $book ]] &&\ expr+=" && \$Directory =~ /${prefix}${book-[0-9a-z]+}/" [[ -n $page || -n $subpage ]] &&\ expr+=" && \$Filename =~ /${page-[0-9]+}${subpage-[a-z]}-.*-.*\\.jpg/" pst Searching for: $expr >&2 # The expression has to have a true in it for it to work. exiftool -r -if "1 eq 1 $expr" -p "$output" ./Book* ./Annex* | if [[ -n $fehp ]]; then pst Opening Feh if [[ -n $daemon ]]; then feh -d.Sfilename \ -^ "Search results for $search_tags [%u/%l]"\ -f - & else exec feh -d.Sfilename -f - fi else sort fi
Raw
Annotate
Repaste