#!/bin/bash

while [[ $chosen != 'chosen' ]]; do
  clear
  echo -e "============================================\033[1;38;5;94m"
  ls $HOME/.Books/backgrounds
  echo -e "\033[38;5;95m============================================"
  cd $HOME/.Books/backgrounds
  read -e -p " Choose a background:$(echo -e "\033[1;38;5;94m") " bg
  if [[ -e "$bg" && "$bg" =~ \.(jpg|jpeg)$ ]]; then
    echo
    $HOME/.Books/viu "$bg" -w64
    echo
    read -sn1 -p "This one? [Y|n]" yn
    if [[ ! ${yn^^} == 'N' ]]; then
      rm -f $HOME/.Books/backgrounds/atmo.jpg
      ln -s "$(realpath "$bg")" $HOME/.Books/backgrounds/atmo.jpg
      chosen='chosen'
    fi
    echo
  else
    echo Not a .jpg
  fi
done
