Get to your ebooks quickly

2018-11-12 393 words 2 mins read

So this is going to be a little longer post than usual.

To begin with, here is screenshot of how it would look like finally:

We are using “rofi” here to show the menu. So, lets first install that

cat <<EOF >/etc/yum.repos.d/_copr_yaroslav-i3desktop.repo 
[yaroslav-i3desktop]
name=Copr repo for i3desktop owned by yaroslav
baseurl=https://copr-be.cloud.fedoraproject.org/results/yaroslav/i3desktop/fedora-$releasever-$basearch/
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=https://copr-be.cloud.fedoraproject.org/results/yaroslav/i3desktop/pubkey.gpg
repo_gpgcheck=0
enabled=1
EOF

yum install rofi
Once that is done, we will create a small script to look for all our pdf files and display that in the menu, like above. Save this as ~/bin/books-search.sh :
 
#!/usr/bin/env bash
#
# wget 'https://raw.githubusercontent.com/miroslavvidovic/rofi-scripts/master/books-search/books-search.sh'

—————————————————————————–

Info:

author: Miroslav Vidovic

file: books-search.sh

created: 13.08.2017.-08:06:54

revision: —

version: 1.0

—————————————————————————–

Requirements:

rofi

Description:

Use rofi to search my books.

Usage:

books-search.sh

—————————————————————————–

Script:

Modified by Amit Agarwal

Books directory

BOOKS_DIR=/usr/share/texlive/texmf-dist/doc/

Save find result to F_ARRAY

readarray -t F_ARRAY <<< “$(find “$BOOKS_DIR” -type f -name ‘*.pdf’)”

Associative array for storing books

key => book name

value => absolute path to the file

BOOKS[‘filename’]=‘path’

declare -A BOOKS

Add elements to BOOKS array

get_books() { for i in “${!F_ARRAY[@]}” do path=${F_ARRAY[$i]} file=$(basename “${F_ARRAY[$i]}”) BOOKS+=(["$file"]="$path") done }

List for rofi

gen_list(){ for i in “${!BOOKS[@]}” do echo “$i” done }

main() { get_books

book=$( (gen_list) | rofi -dmenu -lines 10 -width 100 -i -matching fuzzy -only-match -location 0 -fake-transparency -p “Book > " ) book=$( (gen_list) | rofi -dmenu -i -matching fuzzy -only-match -p “Book > " ) xdg-open “${BOOKS[$book]}” }

main exit 0

In the above script, change the BOOKS_DIR to the one that you would like to see. And finally make some cosmetic changes:
cat <<EOF >~/.Xresources 
rofi.color-enabled: true
rofi.opacity:                        50
rofi.width:                          100
rofi.lines:                          10
rofi.columns:                        4
rofi.font:                           System San Francisco Display 8
rofi.color-normal:                   #fdf6e3,#002b36,#eee8d5,#586e75,#eee8d5
rofi.color-urgent:                   #fdf6e3,#dc322f,#eee8d5,#dc322f,#fdf6e3
rofi.color-active:                   #fdf6e3,#268bd2,#eee8d5,#268bd2,#fdf6e3
rofi.color-window:                   #fdf6e3,#002b36
rofi.yoffset:                        0
rofi.xoffset:                        0
rofi.fixed-num-lines:                false
rofi.terminal:                       rofi-sensible-terminal
rofi.ssh-client:                     ssh
rofi.ssh-command:                    {terminal} -e {ssh-client} {host}
rofi.run-command:                    {cmd}
rofi.run-list-command:               
rofi.run-shell-command:              {terminal} -e {cmd}
rofi.window-command:                 xkill -id {window}
rofi.disable-history:                false
rofi.levenshtein-sort:               false
rofi.case-sensitive:                 false
rofi.cycle:                          true
rofi.sidebar-mode:                   false
rofi.auto-select:                    false
rofi.parse-hosts:                    true
rofi.parse-known-hosts:              true
rofi.combi-modi:                     window,run
rofi.fuzzy:                          true
rofi.glob:                           false
rofi.regex:                          false
rofi.tokenize:                       true
rofi.m:                              -1
rofi.line-margin:                    2
rofi.filter:                         
rofi.separator-style:                dash
rofi.hide-scrollbar:                 false
rofi.fullscreen:                     false
rofi.fake-transparency:              true
rofi.dpi:                            -1
rofi.threads:                        1
rofi.scrollbar-width:                8
rofi.scroll-method:                  0
rofi.fake-background:                screenshot
rofi.display-ssh:                    
rofi.display-run:                    
rofi.display-drun:                   
rofi.display-combi:
EOF

xrdb -merge ~/.Xresources

Finally for easy access, you might want to bind a key to lauch the script that we created and voila.

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it