summaryrefslogtreecommitdiff
path: root/bin/menuscripts/mmedia
blob: 5d7c4ae054ec2c67cf5d415e7604317b16419975 (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
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env sh

tmp="/tmp/mmedia"

dirs="$HOME/dl"

concat_path() { sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g"; }

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"; } ;;
	"cursus")
		regex='^.*/[cC]ursus/index.html$'
		dirs="$HOME/docs/school"
		concat_path() { cat; }
		viewer() { $BROWSER "$1"; } ;;
	*) 
		choice="$(cat <<-EOF | commander -d -c
		video
		pdf
		images
		cursus
		EOF
		)"
		[ "$choice" ] || exit 1
		"$0" "$choice"
		exit ;;
esac

shift
[ "$1" ] && dirs="$1"

choice="$(find -L $dirs 2> /dev/null |
	grep "$regex" |
	sort | tee "$tmp" |
	concat_path |
	commander -c -d -n -x)"

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

viewer "$file"