summaryrefslogtreecommitdiff
path: root/.local/bin/linkhandler
blob: a4904e1eea02516795170d9e930c1ee45d5f35d8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

note()
{
	command -v notify-send > /dev/null &&
		notify-send "  linkhandler" "$1"
}

########
# MAIN #
########

[ -z "$1" ] &&
	exec "${BROWSER:-firefox}"

case "${1%/}" in
*mp3|*flac|*opus|*mkv|*webm|*mp4|*youtube.com/watch*|\
*youtube.com/playlist*|*youtu.be*|*bitchute.com*|*videos.lukesmith.xyz*|\
*piped.kavin.rocks*|*inv.vern.cc*|*yewtu.be*)
	note "streaming media"
	exec mpv -quiet "$1" > /dev/null 2>&1
	;;
*.png|*.jpg|*.jpeg|*.gif|*.webp|*.pdf|*.cbz|*.cbr)
	note "processing file"
	curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" &&
		exec xdg-open "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" > /dev/null 2>&1 &
	;;
*.c|*.cpp|*.sh|*.txt|*.java|*.nix|*.lua)
	note "processing text"
	curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" &&
		exec xdg-open "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" > /dev/null 2>&1 &
	;;
*)
	if echo "$1" | grep -Eqx '^https?://[^/]*\.onion(/.*)?'; then
		if ! command -v tor-browser > /dev/null; then
			note "tor browser not installed"
			exit 1
		fi
		exec tor-browser "$1" >/dev/null 2>&1
	else
		exec "$BROWSER" "$1" >/dev/null 2>&1
	fi
	;;
esac