#!/bin/rc
targ=$1
scheme=`{echo $targ | cut -d: -f1}

fn bymime(mt) {
	switch ($mt) {
		case application/pdf
			exec zathura $targ
		case image/svg+xml
			exec firefox $targ
		case image/*
			exec imv $targ
		case *openxml*
			exec libreoffice $targ
		default {
			echo "Don't know how to open $targ ($mt)"
			exit 1
		}
	}
}

switch ($scheme) {
	case http
		exec firefox $targ
	case https
		exec firefox $targ
	case mailto
		exec aerc $targ
	default {
		bymime `{file --mime-type $targ | awk '{ print $NF }'}
	}
}
