about summary refs log tree commit diff stats
path: root/bin/lh
diff options
context:
space:
mode:
authorEnsa <psychoticfervor@tuta.io>2019-12-20 00:14:09 -0800
committerEnsa <psychoticfervor@tuta.io>2019-12-20 00:14:09 -0800
commit4684d80b6271dd775cd23dabf2b91d6ce56fa33a (patch)
treeddb6c6219e213132b8500e016b1ce238aa71029d /bin/lh
parentf733ca7c8041866df27752c8e0c2610e0ecef6a7 (diff)
downloadcfg-4684d80b6271dd775cd23dabf2b91d6ce56fa33a.tar.gz
first significant commit
see README.md for information
Diffstat (limited to 'bin/lh')
-rwxr-xr-xbin/lh37
1 files changed, 37 insertions, 0 deletions
diff --git a/bin/lh b/bin/lh
new file mode 100755
index 0000000..e4bdf0c
--- /dev/null
+++ b/bin/lh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# lh: the Link Handler
+# takes one path or URL as its argument, launches the appropriate program for this.
+### differs from Luke Smith's linkhandler in cleaner code, inclusion of epub/pdf handling, proper interpretation of twitch video URLs, and livestream handling with streamlink (twitch only for now, tipping me off to URL schemes to look for for other streaming sites would be appreciated.)
+
+# if $1 isn't provided, spawn $BROWSER and exit. this allows lh to be used as a pseudo-browser.
+[ -z "$1" ] && exec "$BROWSER"
+
+case "$1" in
+	*mkv|*webm|*mp4)
+		mpv --input-ipc-server=/tmp/mpv-socket$(date +%s) --quiet "$1" >/dev/null 2>&1 & ;;
+	*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*)
+		mpv --input-ipc-server=/tmp/mpv-socket$(date +%s) --quiet --ytdl "$1" >/dev/null 2>&1 & ;;
+	*twitch.tv/*)
+		STREAMQUAL="$(streamlink "$1"|\
+			grep "Available streams"|tr " " "\n"|grep -E "[0-9]"|tr -d ,|\
+			dmenu -p "choose stream quality for $1")"
+		streamlink -p mpv $1 $STREAMQUAL >/dev/null 2>&1 & ;;
+	*png|*jpg|*jpe|*jpeg|*gif)
+		IMGPATH="/tmp/$(echo "$1"|sed "s/.*\\///")"
+		curl -sL "$1" >"$IMGPATH"&&sxiv -a "$IMGPATH">/dev/null 2>&1 & ;;
+	*mp3|*m4a|*flac|*aiff|*opus|*mp3?source*)
+		curl -LO "$1" >/dev/null 2>&1 & ;;
+	*epub|*pdf|*djvu)
+		BOOKPATH="/tmp/$(echo "$1"|sed "s/.*\\///")"
+		if [ -n "$READER" ]; then
+			curl -sL "$1" >"$BOOKPATH"&&$READER "$BOOKPATH">/dev/null 2>&1 &
+		else
+			curl -sL "$1" >"$BOOKPATH" &
+		fi ;;
+	*)
+		if [ -f "$1" ]; then
+			$TERMINAL -e "$EDITOR $1"
+		else
+			$BROWSER "$1" >/dev/null 2>&1 &
+		fi ;;
+esac