Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

36 lines
987 B

  1. #!/bin/sh
  2. # This is a small script to open a book from your calibre library
  3. # Using dmenu.
  4. LIBRARY="$HOME/Library"
  5. if [ "$(date -r "$XDG_CACHE_HOME/calibrelib" "+%d-%m-%Y")" = "$(date '+%d-%m-%Y')" ]; then
  6. books_raw=$(cat "$XDG_CACHE_HOME/calibrelib")
  7. else
  8. books_raw=$(calibredb --with-library "$LIBRARY" list --for-machine --fields="title,authors,formats")
  9. fi
  10. id="$(echo "$books_raw" |\
  11. jq -r '.[]|(.id | tostring) + " | " + .title + " | " + .authors' |\
  12. dmenu -i -l 12 -p "Search Book: " |\
  13. cut -d "|" -f 1)"
  14. entry="$(echo "$books_raw" | jq -a ".[]|select(.id | contains($id))")"
  15. formats="$(echo "$entry" | \
  16. jq -r ".formats|.[]" |\
  17. sed -r "s/.*\.([^\.]*)$/\1/g")"
  18. if [ "$(echo "$formats" | wc -l)" -lt 2 ]; then
  19. xdg-open "$(echo "$entry" | \
  20. jq -r ".formats|.[0]")"
  21. exit
  22. fi
  23. index=$(( $(echo "$formats" | grep -n -F $(echo "$formats" | \
  24. dmenu -p "Select format:" ) | cut -d ":" -f 1) - 1))
  25. xdg-open "$(echo "$entry" | \
  26. jq -r ".formats|.[$line]")"