-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen_reference
More file actions
executable file
·27 lines (21 loc) · 1.06 KB
/
open_reference
File metadata and controls
executable file
·27 lines (21 loc) · 1.06 KB
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
#!/usr/bin/env bash
# Program to display list of references in a user-specified folder, choose one from it and open it.
# An array of folders of interest. Each entry must be of the form
# folder_shortname - full/path/to/folder
declare -a folders=(
"references - /home/bharath/Desktop/a-tale-of-two-dead-stars/references"
"misc_reading - /home/bharath/Desktop/misc_reading"
)
while [ -z "$folder" ]
do
folderchoice=$(printf '%s\n' "${folders[@]}" | dmenu -i -c -bw 2 -l 20 -p 'Choose head folder:') || exit
folderpath=$(echo "$folderchoice" | awk '{print $NF}')
folder=$(echo "$folderchoice" | awk '{print $1}')
done
reference=$(ls $folderpath/*.pdf $folderpath/*.djvu | sed "s:/.*/::g" | dmenu -i -bw 2 -c -l 20 -g 2 -p "Choose reference from ${folder}:")
# If no file chosen, exit quietly.
[ -z "$reference" ] && exit
# If file chosen exists, open and exit.
[ -e "$folderpath/$reference" ] && (zathura "$folderpath/$reference" &) && exit
# If file chosen doesn't exist, complain and exit.
[ ! -e "$folderpath/$reference" ] && echo "Error: "$reference" not found!" && exit 1