about summary refs log blame commit diff stats
path: root/bin/lh
blob: 25a2f62ae4354fb9022fcc95c0927ff4d4586800 (plain) (tree)
1
2
3
4
5
6
7
8


                                                                                   


                                                                                               

                        


                                                                                                                                 







                                                                                      

                                                      













                                                                                        
#!/bin/sh
# lh: the Link Handler
# takes one path or URL as its argument, launches the appropriate program for this.

# 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 "$1" >/dev/null 2>&1 & ;;
	*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*twitch.tv/videos/*|*twitch.tv/*/v/*)
		mpv --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|*ogg|*mp3?source*)
		mpv "$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