I save images under names made up of keywords:
$ ls -t | head
politiciansstupidaoc.jpg
taxesfinancemoneydebate.jpeg
vaccinesdebate7.jpeg
collectivismronpaulracism.png
religionviolencecultfascism.jpeg
facebookprivacysurveillance.jpg
coronavirusfakemediacancerage.png
epsteinkeanureeves.jpeg
usaconstitutioncdctechnocracy.png
mindcontrolmanipulationstupiditywater.jpeg

I wrote this script to browse them. Do you think I chose the right solution? It is short but a bit messy.

#!/bin/bash

#
# browse keyword named images
# . brim.sh {[num] [dir]}|[dir num] [filter ...]
# num: number of newest images to show
# dir: directory of images
# filter: string of chars to filter by
#
#

# allows selection of recent files
# does not break blanks

# set -x

shopt -s extglob
# required for command only (not when sourced)

head=0
dir=./
if [ -d "$1" ]; then
dir=$1/; shift
if [[ $1 =~ ^[[:digit:]]+$ ]]; then
head=$1; shift; fi
else
if [[ $1 =~ ^[[:digit:]]+$ ]]; then
head=$1; shift
if [ -d "$1" ]; then
dir=$1/; shift; fi; fi; fi

echo "$dir"*.@(jpg|jpeg|png|gif|webp) | grep -q @ && echo "***" no image files in "$dir" && exit

found=false
{ while read; do
file=$(basename "$REPLY")
sel=true
for s in "$@"; do
[[ $file != *$s* ]] && sel=false && break; done
[ $sel = true ] && found=true && echo "$REPLY"; done \
< <(ls -t "$dir"*.@(jpg|jpeg|png|gif|webp))
[ $found = false ] && echo "***" nothing found > $(tty); } \
| if ((head)); then head -n$head; else cat; fi \
| xargs -rd\\n eog -f
# when only one image found, eog browses the other images
I save images under names made up of keywords: $ ls -t | head politiciansstupidaoc.jpg taxesfinancemoneydebate.jpeg vaccinesdebate7.jpeg collectivismronpaulracism.png religionviolencecultfascism.jpeg facebookprivacysurveillance.jpg coronavirusfakemediacancerage.png epsteinkeanureeves.jpeg usaconstitutioncdctechnocracy.png mindcontrolmanipulationstupiditywater.jpeg I wrote this script to browse them. Do you think I chose the right solution? It is short but a bit messy. #!/bin/bash # # browse keyword named images # . brim.sh {[num] [dir]}|[dir num] [filter ...] # num: number of newest images to show # dir: directory of images # filter: string of chars to filter by # # # allows selection of recent files # does not break blanks # set -x shopt -s extglob # required for command only (not when sourced) head=0 dir=./ if [ -d "$1" ]; then dir=$1/; shift if [[ $1 =~ ^[[:digit:]]+$ ]]; then head=$1; shift; fi else if [[ $1 =~ ^[[:digit:]]+$ ]]; then head=$1; shift if [ -d "$1" ]; then dir=$1/; shift; fi; fi; fi echo "$dir"*.@(jpg|jpeg|png|gif|webp) | grep -q @ && echo "***" no image files in "$dir" && exit found=false { while read; do file=$(basename "$REPLY") sel=true for s in "$@"; do [[ $file != *$s* ]] && sel=false && break; done [ $sel = true ] && found=true && echo "$REPLY"; done \ < <(ls -t "$dir"*.@(jpg|jpeg|png|gif|webp)) [ $found = false ] && echo "***" nothing found > $(tty); } \ | if ((head)); then head -n$head; else cat; fi \ | xargs -rd\\n eog -f # when only one image found, eog browses the other images
0 Comments 0 Shares 13575 Views