Storage for XML files used to represent Dante's *Divine Comedy*.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

60 lines
1.6 KiB

#!/bin/bash
# An interactive xpath query tool
touch .prev-xpath.tmp
GREEN='\033[0;32m'
NC='\033[0m' # no color
clear
read -p "Choose a canto: [i,r,p][1-34]" CANTO
CANTICLE="$(echo $CANTO | tr -d -c a-z)"
CANTO_NUM="$(echo $CANTO | tr -d -c 0-9)"
file="-${CANTO_NUM}.xml"
if [[ "$CANTICLE" == 'i' ]]; then
CANTICLE='Inferno'
file="inferno${file}"
elif [[ "$CANTICLE" == 'r' ]]; then
CANTICLE='Purgatorio'
file="purgatorio${file}"
elif [[ "$CANTICLE" == 'p' ]]; then
CANTICLE='Paradiso'
file="paradiso${file}"
else
echo "Not a valid canto file: $file"
fi
if [[ -e "$file" ]]; then
clear && echo -e "You are searching ${CANTICLE^} ${CANTO_NUM}.\nAdd a trailing slash ${GREEN}\`/\`${NC} to your search before submitting it. The default first two search choices are ${GREEN}\`canto\`${NC} and then ${GREEN}\`terzine\`${NC}. Press ${GREEN}<enter>${NC} for those defaults and type something else to search that.\n"
i='0'
read -p "Load previous: (Y)/n " PREV
case "$PREV" in
N|n)
search=''
;;
Y|y|*)
search="$(cat .prev-xpath.tmp)"
;;
esac
while true; do
read -e -i "$search" -p "$(echo -e "\nSearch: \n "${GREEN}"===> "${NC})" nsearch
if [[ "${nsearch: -1}" == '/' ]]; then # if last char trailing slash then search
path="${nsearch::-1}"
echo "$path" > .prev-xpath.tmp # remove trailing slash
xmllint --xpath "$path" $file | batcat -l 'xml'
exit
elif [[ "$i" == '0' ]] && [[ "$nsearch" == '' ]]; then
search="/canto"
elif [[ "$nsearch" == '/canto' ]]; then
search="/canto/terzine"
else
search="${nsearch}"
fi
i=$[$i+1]
done
else
echo "Canto file not found. What directory are you in?"
fi