aboutsummaryrefslogtreecommitdiff
path: root/public/.local/bin/dmenu-openbook.sh
blob: e5766d544315c32ea83d23d27c31a1c520d04bd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
# xdg-open a file selected through dmenu
# TODO: merge dmenu-open* into dmenu-open.sh, call it with 1 argument:
#       `dmenu-open.sh books|spreadsheet`
#       `dmenu-open.sh` with no arguments opens a preliminary dmenu to select
#       the category (base directory) from a list.  Each category is defined by
#       a path and white-listed file extensions.

path="$HOME/docs/books"

notify() {
    mimetype=$(xdg-mime query filetype "$selected")
    defaultprogram=$(xdg-mime query default "$mimetype")
    notify-send "Opening $selected ($mimetype) with $defaultprogram"
}

cd $path
files=$(find . -type f \( -iname "*.pdf" -o -iname "*.epub" \))
selected=$(echo "$files" | dmenu -i -l 20 -p "Select book:")
if [ -n "$selected" ]; then
    xdg-open "$selected" &
    notify
fi