#!/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