summaryrefslogtreecommitdiff
path: root/bin/menuscripts/mmedia
blob: bd31a584e9446c298106d81a3ae60aae65e73692 (plain)
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 sh

tmp="/tmp/mmedia"

dirs="$HOME/dl"

case "$1" in 
	"video") 
		regex='^.\+\.\(webm\|mp4\|mpeg\|mkv\)$' 
		dirs="$dirs $HOME/vids"
		viewer() { mpv "$1"; } ;;
	"pdf") 
		regex='^.\+\.\(pdf\)$' 
		dirs="$dirs $HOME/docs"
		viewer() { zathura "$1"; } ;;
	"images")
		regex='^.\+\.\(png\|avif\|jpg\)$' 
		dirs="$dirs $HOME/pics"
		viewer() { imv "$1"; } ;;
	*) 
		choice="$(cat <<-EOF | commander -d -c
		video
		pdf
		images
		EOF
		)"
		[ "$choice" ] || exit 1
		"$0" "$choice"
		exit 1 ;;
esac

choice="$(find -L $dirs 2> /dev/null |
	grep "$regex" |
	sort | tee "$tmp" |
	sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g" |
	commander -c -d -n -x)"

file="$(sed -n "${choice}p" "$tmp")"
[ -r "$file" ] || exit 1

viewer "$file"