summaryrefslogtreecommitdiff
path: root/opener
blob: 2903949890e7872a972b0b6ae2651963310ff384 (plain)
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
#!/bin/sh
ORIGIN_VIEW="?"
while getopts f: opt; do
	case $opt in
	f) ORIGIN_VIEW=$OPTARG;;
	\?) echo "Usage: $0 [-f view] mime_type base_address file" >&2; exit 1;;
	esac
done
shift `expr $OPTIND - 1`
case "$1" in
	application/pdf) VIEWER=zathura;;
	image/*) VIEWER=sxiv;;
	text/html*) VIEWER=viewhtml;;
	text/*) VIEWER=less;;
	*) echo "\e[31m$1\e[0m $2 $3" >&2; exit 1;;
esac
if [ $VIEWER = $ORIGIN_VIEW ]; then
	echo "$2 $3"
	exit 0
else
	case $VIEWER in
		zathura | sxiv | less) setsid $VIEWER $3;;
		viewhtml) setsid $VIEWER $3 $2;;
		*) echo "\e[31m$VIEWER\e[0m $@" >$2; exit 1;;
	esac
fi
exit 0