From b9fff4912bda1e116338a8749bffbba830891e71 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Thu, 20 Aug 2020 15:57:16 +0200 Subject: [PATCH] Initiate generic open script --- local/bin/open | 40 ++++++++++++++++++++++++++++++++++++++++ local/bin/open.sh | 5 ----- 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100755 local/bin/open delete mode 100755 local/bin/open.sh diff --git a/local/bin/open b/local/bin/open new file mode 100755 index 0000000..1a9c7cb --- /dev/null +++ b/local/bin/open @@ -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" diff --git a/local/bin/open.sh b/local/bin/open.sh deleted file mode 100755 index e98f8e6..0000000 --- a/local/bin/open.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -curl -IL "$1" \ - | grep Content-Type \ - | tail -n 1 \ - | grep image && rifle "$1" || xdg-open "$1"