~yerinalexey/dotfiles

ref: a6f69665f838d05c0a1abb78974bc9888b8efb2c dotfiles/scripts/xdg-open -rwxr-xr-x 817 bytes
a6f69665Alexey Yerin scripts/xdg-open: handle gemini links 2 months ago
                                                                                
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
45
46
47
48
49
#!/bin/sh

# Less annoying xdg-open
#
# The original xdg-open is a pain to configure and work with. We need
# something simpler.

# MIME type handlers
open_mime() {
	mimetype="$(file --mime-type -b "$1")"

	case "$mimetype" in
		application/pdf)
			exec $READER "$1"
			;;
		image/*)
			exec $IMAGE "$1" &
			;;
		video/*)
			exec $VIDEO --no-terminal "$1" &
			;;
		audio/*)
			exec $VIDEO --no-terminal --force-window --loop "$1" &
			;;
		*)
			exec /usr/bin/xdg-open "$@" >/dev/null 2>&1 &
			;;
	esac
}

# This %%:* magic gets part of the string until ":"
# ("*" matches to the end of the line)
case ${1%%:*} in
	# Web
	https|http)
		exec $BROWSER "$1" 2>/dev/null >/dev/null &
		;;
	gemini)
		exec $TERMINAL amfora "$1" &
		;;
	mailto)
		exec $TERMINAL aerc "$1" &
		;;

	# Files
	*)
		open_mime "$@"
		;;
esac