#!/bin/bash

#This script opens a telnet connection in the 68k Blit terminal emulator. The
#URL is in the format telnet_blit://<host>[:<port>] and a blit_roms directory
#with Blit ROM images must be present in the current directory.

if [ ! "$1" ]
then
	echo "no URL provided" >&2
	exit 1
fi

if ! echo "$1" | grep -q '^telnet_blit://' 2>/dev/null >/dev/null
then
	echo "URL does not start with telnet_blit://" >&2
	exit 1
fi

host_port="`echo $1 | sed 's,telnet_blit://,,' | sed 's/:/!/'`"

if ! cd blit_roms
then
	echo "no blit_roms directory found" >&2
	exit 1
fi
exec blit -t "tcp!$host_port"
