-
Notifications
You must be signed in to change notification settings - Fork 5
/
mylib-improved
41 lines (34 loc) · 1.11 KB
/
mylib-improved
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
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env bash
# Written By Woland
# List PDFs in given directory and opens selection in zathura
#Dependency:
# dmenu fd zathura
# PDFs are assumed to be in ~/Downloads/Document & ~/Documents
# https://github.com/wolandark
# https://github.com/wolandark/BASH_Scripts_For_Everyone
search_dirs=("$HOME/Downloads/Documents" "$HOME/Documents")
declare -A file_paths
function findFiles() {
while IFS= read -r file; do
file_paths["$file"]=$(basename "$file")
done < <(fd --type f --extension pdf --extension epub --extension djvu "" "${search_dirs[@]}")
}
function sendToDmenu() {
if selection=$(printf '%s
' "${file_paths[@]}" | dmenu -p 'Library:' -l 15 -fn 'monospace-12' -nb '#282828' -nf '#fbf1c7' -sb '#458588' -sf '#000' -l 20); then
for path in "${!file_paths[@]}"; do
if [[ "${file_paths[$path]}" == "$selection" ]]; then
echo "Opening: $path"
zathura "$path"
break
fi
done
else
echo "No selection made or dmenu closed."
fi
}
function main() {
findFiles
sendToDmenu
}
main