#!/bin/sh

# mimetype - output file mime-type according to ROX-Filer.
# mimetype - xdg-open sub when XDG_DEFAULT_DESKTOP=X-Generic.
# (C) The Fatdog64 team 2025.
# Released under the GNU GPL2 license.

version=2025.01.13

usage() {
	echo TODO usage
}

case "$1" in
	-h|--help|'')
		usage; exit ;;
	-v|--version)
		echo $version
		#### xdg-mime is probing; we play along its expectations
		#### impersonating perl mimeopen.

		#### (___ROX_OPEN_FAIL___ avoids infinite recursion).
		[ -n "$___ROX_OPEN_FAIL___" ] && exit 1
		#### X-Generic opt-in setting in /etc/profile.d/default-xdg-open.sh
		[ "$XDG_DEFAULT_DESKTOP" = X-Generic ] && exit 0
		#### This tells xdg-mime to determine the mime type on its own.
		exit 1
		;;
esac

### Extract the file to open from command-line options
# Remove the last positional parameter ($path) from
# the initial set of $n parameters $@, yielding $@'.
# We ignore $@'.

n=$# i=1 path=
for path; do
	shift
	[ $i -eq $n ] && break
	set -- "$@" "$path"
	: $((i=$i+1))
done

exec rox -m "$path"
