aboutsummaryrefslogtreecommitdiff
path: root/extras/HOME/.local/bin/library-view.sh
blob: 3bb4211093902b1546dcf1566c1aa105b1ba645d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash

MENU=(rofi -i -dmenu -sort -theme-str '* {theme-color: #ff88ff;}' -p "Library")

if (which zathura) ; then
  pdfviewer=zathura
elif (which evince) ; then
  pdfviewer=evince
else
  pdfviewer='xdg-open'
fi

if [ ! -e ~/Library ] ; then
  mkdir -p ~/Library
fi


cd ~/Library

file_with_title="$(find . -name '*.pdf' | while read file ; do
  echo "$file| $(echo "$file" | sed \
  's#\(^\|_\|\s\)\([a-z]\)#\1\U\2#g;s/\.[^.]*$//;s#^\(.*\)/\([^/]*\)$#\2 (\1)#' | tr '_' ' ')"
done)"

selected=$(echo "$file_with_title" | (while read file ; do
  echo "${file//*|}"
done) | "${MENU[@]}")

if [ ! -z "${selected}" ] ; then
  $pdfviewer "$(echo "$file_with_title" | grep "$selected" | sed 's/|.*//')"
fi