summaryrefslogtreecommitdiff
path: root/bin/menuscripts/mmedia
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-06 15:29:58 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-06 15:29:58 +0200
commitad05cb18f03f3a97a918e090c38ba760147a0bb6 (patch)
tree233097b3ccbf1a4fef18a291d0d8fda3fba34c03 /bin/menuscripts/mmedia
parent1a7e35285abb5db60d2e1544ce0100e82c5d3490 (diff)
parent511b6c1bc9acd9e6029d08a6c448f6e0037755fb (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin/menuscripts/mmedia')
-rwxr-xr-xbin/menuscripts/mmedia59
1 files changed, 59 insertions, 0 deletions
diff --git a/bin/menuscripts/mmedia b/bin/menuscripts/mmedia
new file mode 100755
index 0000000..63d3f7b
--- /dev/null
+++ b/bin/menuscripts/mmedia
@@ -0,0 +1,59 @@
+#!/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() { $PLAYER "$1"; } ;;
+ "pdf")
+ regex='^.\+\.\(pdf\)$'
+ dirs="$dirs $HOME/docs"
+ viewer() { $VIEWER "$1"; } ;;
+ "image")
+ regex='^.\+\.\(png\|avif\|jpg\)$'
+ dirs="$dirs $HOME/pics"
+ viewer() { $IMAGE "$1"; } ;;
+ "cursus")
+ regex='^.*/[cC]ursus/index.html$'
+ dirs="$HOME/docs/school/Vakken"
+ concat_path() { sed "s#$dirs/##;s#/[cC]ursus/index.html##"; }
+ viewer() { $BROWSER "$1"; } ;;
+ "schoolpdf")
+ regex='^.\+\.\(pdf\)$'
+ dirs="$HOME/docs/school/Vakken"
+ concat_path() { sed "s#$dirs/##;s#/[cC]ursus/index.html##;s#/Cursus/viewer/files/#: #"; }
+ viewer() { $VIEWER "$1"; } ;;
+ *)
+ choice="$(cat <<-EOF | dmenu -g 5 -l 1 -c
+ video
+ pdf
+ image
+ cursus
+ schoolpdf
+ 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 |
+ dmenu -px -c -n -x -l 10 -g 1 -F)"
+
+file="$(sed -n "${choice}p" "$tmp")"
+[ -r "$file" ] || exit 1
+
+viewer "$file"