The Easy-To-Use Bash-Menu Version
#!/bin/bash
[ -t 1 ] || exit
shopt -s nullglob
declare -u choice
B=$(tput bold) #Bold
G=$(tput setaf 2)${B} #Green+bold
N=$(tput sgr0) #reset to Normal
title="${B}BRAVE BROWSER BACKGROUND BUTLER${N}"
status="$title"
WriteRecord()
{
author=${1%%_*}
cat<<RECORD
"name":"unused",
"source":"${1}",
"author":"${author//-/ }",
"link":"https://community.brave.com/",
"originalUrl":"unused",
"license":"unused"
RECORD
}
Generate()
{
unset x
echo -e '{"schemaVersion":1,\n\t"images":[{'
for picname in "${picdir}/"*{webp,png,jpg,jpeg,avif}
do
[ $x ] && echo -e '\t},{' || x=set
WriteRecord "${picname##*/}"
done
echo -e '\t}\n]}'
}
Menu()
{
while :
do
clear
cat<<-MENU
$status
[${B}O${N}]pen Wallpaper Directory
[${B}E${N}]dit index (Photo.json)
[${B}G${N}]enerate index (Photo.json)
[${B}Q${N}]uit
MENU
read -s -n1 choice ; status="$title"
case "$choice" in
O) caja "$picdir" ; status="${G}Caja launched${N}" ;;
E) pluma "$index" & status="${G}Pluma launched${N}" ;;
G) Generate >"$index" ; status="${G}Photo.json generated${N}" ;;
Q) exit ;;
esac
done
}
exec 3< <( find $HOME/.config -name "manifest.json" )
while read -u3 manifest
do
if grep "Brave NTP background images component" "$manifest" &>/dev/null
then
index="${manifest/manifest.json/photo.json}"
picdir="${manifest%/*}"
cp -n "${index}" "${index}.original"
[ $(wc -l <"${index}") -lt 3 ] && sed -i "s|,|,\n|g" "${index}"
Menu
fi
done
P.S. this posted code will be updated for minor optimizations.