Get to your ebooks quickly

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.

change the output format for time command

If you are doing some scripting and using ‘time’ command, then you know sometimes it becomes difficult to capture the output as the output would be something like this:

: amit ; time ls

real    0m0.002s
user    0m0.000s
sys 0m0.001s

So, it is better to change that format. Here is simple example:

1
 
TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
amit ;  TIMEFORMAT=’real %3R user %3U sys %3S pcpu %P’ time ls
0.00user 0.00system 0:00.00elapsed 0%CPU (0text+0data 2432max)
0inputs+0outputs (0major+109minor)pagefaults 0swaps
amit ; TIMEFORMAT=’real %3R user %3U sys %3S’
amit ; time ls
real 0.001 user 0.001 sys 0.000
amit ;
amit ; TIMEFORMAT=’TIMEOUTPUT = real %3R user %3U sys %3S’
amit ; time ls
TIMEOUTPUT = real 0.001 user 0.001 sys 0.000
amit ;

image ordering by Original Date Time using bash script

Here is the script:

#!/bin/bash -
#===============================================================================
#
#          FILE: imgOrg.sh
#
#         USAGE: ./imgOrg.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka)
#      REVISION:  ---
#===============================================================================

for i in *
do
    if [[ $(file $i) == *image* ]] 
    then
        echo "Image file is :: $i"
        dir=$( exiftool -s -DateTimeOriginal $i | awk -F':' '{print $2"/"$3}')
        mkdir -p $dir
        cp $i $dir/
    else
        echo "Excluding $i"
    fi
done

 

Script looks at the DateTimeOriginal parameter in output of exiftools ( which is basically the date and time image was taken) and then puts the images in the folder in format YYYY/MM.