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.

37 lines
1.0 KiB

  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. echo "$books_raw" > "$XDG_CACHE_HOME/calibrelib"
  10. fi
  11. id="$(echo "$books_raw" |\
  12. jq -r '.[]|(.id | tostring) + " | " + .title + " | " + .authors' |\
  13. dmenu -i -l 12 -p "Search Book: " |\
  14. cut -d "|" -f 1)"
  15. entry="$(echo "$books_raw" | jq -a ".[]|select(.id | contains($id))")"
  16. formats="$(echo "$entry" | \
  17. jq -r ".formats|.[]" |\
  18. sed -r "s/.*\.([^\.]*)$/\1/g")"
  19. if [ "$(echo "$formats" | wc -l)" -lt 2 ]; then
  20. xdg-open "$(echo "$entry" | \
  21. jq -r ".formats|.[0]")"
  22. exit
  23. fi
  24. index=$(( $(echo "$formats" | grep -n -F $(echo "$formats" | \
  25. dmenu -p "Select format:" ) | cut -d ":" -f 1) - 1))
  26. xdg-open "$(echo "$entry" | \
  27. jq -r ".formats|.[$line]")"