#!/bin/sh # showKingdom.sh: Shows the images of a card list received as input # # Needs card images in ./local/share/dominion/cards # # Usage: showKingdom.sh [-oi] scriptName="${0##*/}" usageMessage="Usage: ${scriptName} [-oi]" error() { printf '%s error: %s\n' "$scriptName" "$*" >&2 } errorAndUsage() { printf '%s error: %s\n%s\n' "$scriptName" "$*" "$usageMessage" >&2 } dir="${HOME}/.local/share/dominion/cards" if ! [ -d "$dir" ]; then error "Needed ${dir} directory not found." exit 1 fi PRINT_SELECTION='' OUTPUT_AS_IMAGE='' TMP_IMAGE='showKingdom.jpg' type 'sxiv' >/dev/null 2>&1 || OUTPUT_AS_IMAGE='y' # Process options while getopts 'oi' opt; do case $opt in 'o' ) PRINT_SELECTION='y' ;; 'i' ) OUTPUT_AS_IMAGE='y' ;; '?' ) printf '%s\n' "$usageMessage" >&2 exit 1 esac done shift $((OPTIND - 1)) if [ -n "$PRINT_SELECTION" ] && [ -n "$OUTPUT_AS_IMAGE" ]; then error 'Can not use visually filter cards with this configuration.' exit 1 fi while read -r card; do name="$(echo "$card" | grep -Eo '[A-Za-z].*[A-Za-z]' | sed 's/[ \/]/_/g')" find "${dir}" -name "${name}.jpg" done | if [ -n "$OUTPUT_AS_IMAGE" ]; then oldIFS="$IFS" IFS="$(printf '\n.')" IFS="${IFS%.}" montage $(cat -) -tile '5x' -mode 'concatenate' -background 'black' "$TMP_IMAGE" magick "$TMP_IMAGE" -trim "$TMP_IMAGE" sxiv "$TMP_IMAGE" || termux-open "$TMP_IMAGE" #rm "$TMP_IMAGE" # Problems on phone IFS="$oldIFS" elif [ -n "$PRINT_SELECTION" ]; then sxiv -iotb | sed 's|^/.*/||;s|_| |g;s|.jpg$||' else sxiv -itb & fi