aboutsummaryrefslogtreecommitdiff
path: root/public/.local/bin/dmenu-openbook.sh
blob: 6a257c716b9d29d77fcdaa19aaae712581ec18f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash
# xdg-open a file selected through dmenu

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