#!/usr/bin/env bash

tryexec () {
	prog=$1
	shift
	[[ -x $prog && ! $0 -ef $prog ]] && exec "$prog" "$@"
}

tryexec /usr/local/bin/dtach "$@" ## local or homebrew
tryexec /opt/local/bin/dtach "$@" ## macports
tryexec /usr/bin/dtach "$@" ## os

PATH=$PATH:${0%/*}
case $OSTYPE in
	*darwin*)	exec dtach-osx-amd64 "$@"
			;;
	*linux*)
		case $(uname -m) in
			x86_64) exec dtach-linux64 "$@" ;;
			i[3-6]86) exec dtach-linux32 "$@" ;;
			aarch64) exec dtach-linux-aarch64 "$@" ;;
			*)
				echo "dunno what to do for this arch"
				exit 1
				;;
		esac
		;;
	*)		echo "dunno what to do for this OS"
			exit 1
			;;
esac

# vim:ft=sh:noet:ts=8:sw=8:sts=8
