Initiate generic open script

This commit is contained in:
Felix Van der Jeugt 2020-08-20 15:57:16 +02:00
parent 0a2148bb56
commit b9fff4912b
No known key found for this signature in database
GPG Key ID: 58B209295023754D
2 changed files with 40 additions and 5 deletions

40
local/bin/open Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
set -e
cdtemp() {
dir="$(mktemp --directory --tmpdir open.XXXXXXXX)"
echo "$dir"
cd "$dir"
}
extract() {
echo "$2" | sed "s/$1/\1/"
}
invideous() {
cdtemp
youtube-dl "https://invidio.us/watch?v=$1"
exec mpv *
}
download() {
cdtemp
wget "$1"
caseit *
}
caseit() {
case "$1" in
https://*youtube.com/*) invideous "$(extract '.*v=\([A-Za-z-]*\)' "$1")" ;;
https://youtu.be/*) invideous "$(extract '.*\/\([A-Za-z-]*\)' "$1")" ;;
https://invidio.us/*) invideous "$(extract '.*v=\([A-Za-z-]*\)' "$1")" ;;
http*) download "$1" ;;
esac
case "$(file -b --mime-type "$1")" in
image/*) feh "$1" ;;
video/*) mpv "$1" ;;
esac
}
caseit "$1"

View File

@ -1,5 +0,0 @@
#!/bin/bash
curl -IL "$1" \
| grep Content-Type \
| tail -n 1 \
| grep image && rifle "$1" || xdg-open "$1"