#!/bin/sh

mangadir="$HOME/Pictures/gallery-dl/Manga"
menu1="{{ launcher }} {{ dmenu_flag }} -p Manga"
menu2="{{ launcher }} {{ dmenu_flag }} -p Chapter"

manga=$(find "${mangadir}" -maxdepth 1 -type d -exec basename '{}' \; | tail -n +2 | ${menu1})

if [ -n "$manga" ]
then
  chapter=$(find "${mangadir}/${manga}" -type f -exec basename '{}' \; | ${menu2})
  if [ -n "${chapter}" ]
  then
    zathura "${mangadir}/${manga}/${chapter}"
  else
    $0 "$1"
  fi
fi
