Advertisement
Arafat_H_Rakib

rofi_book_search.sh

May 2nd, 2020
963
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2.  
  3. # -----------------------------------------------------------------------------
  4. # Info:
  5. #   author:    Miroslav Vidovic
  6. #   file:      books-search.sh
  7. #   created:   13.08.2017.-08:06:54
  8. #   revision:  ---
  9. #   version:   1.0
  10. # -----------------------------------------------------------------------------
  11. # Requirements:
  12. #   rofi
  13. # Description:
  14. #   Use rofi to search my books.
  15. # Usage:
  16. #   books-search.sh
  17. # -----------------------------------------------------------------------------
  18. # Script:
  19.  
  20. # Books directory
  21. BOOKS_DIR=~/.dropbox-personal/Dropbox/My-ebooks
  22.  
  23. # Save find result to F_ARRAY
  24. # readarray -t F_ARRAY <<< "$(find "$BOOKS_DIR" -type f \( -name '*.pdf' -o -name '*.epub' \) )"
  25. readarray -t F_ARRAY <<< "$(find "$BOOKS_DIR" -type f \( -iname \*.pdf -o -iname \*.epub -o -iname \*.mobi -o -iname \*.azw3 -o -iname \*.azw2 \))"
  26. # find ./ -type f \( -iname \*.jpg -o -iname \*.png \)
  27.  
  28. # Associative array for storing books
  29. # key => book name
  30. # value => absolute path to the file
  31. # BOOKS['filename']='path'
  32. declare -A BOOKS
  33.  
  34. # Add elements to BOOKS array
  35. get_books() {
  36.     for i in "${!F_ARRAY[@]}"
  37.     do
  38.         path=${F_ARRAY[$i]}
  39.         file=$(basename "${F_ARRAY[$i]}")
  40.         BOOKS+=(["$file"]="$path")
  41.     done
  42. }
  43.  
  44. # List for rofi
  45. gen_list(){
  46.     for i in "${!BOOKS[@]}"
  47.     do
  48.       echo "$i"
  49.     done
  50. }
  51.  
  52. main() {
  53.   get_books
  54.   book=$( (gen_list) | rofi -dmenu -i -matching glob -location 0 -p "E-Books" )
  55.   xdg-open "${BOOKS[$book]}"
  56. }
  57.  
  58. main
  59.  
  60. exit 0
Advertisement
RAW Paste Data Copied
Advertisement