#!/usr/bin/env bash

INSTALLPATH=/usr/local/bin

# allow to pause the script until a keypress 
function pause(){
   read -p "$*"
}

case $1 in
	"")
	echo -e "Usage:\n       html2txt2tags http://URL (requires curl)\n       html2txt2tags file.html\n       html2txt2tags install (to install it into /usr/local/bin)"
	;;
	http://*)
		echo -e "\n\n\n" && curl -s $1 | html2wiki --dialect Txt2tags
        echo -e "\n\n[src $1]\n\n"
		# add ' | sed -r -e "s@^=@\n=@g" ' to create a new line for broken headers
	;;
	install)
	echo -e "We\'ll install this html2txt2tags script to:" ${INSTALLPATH}
		echo "(If you run this script with the correct rights)"
		echo " "
		echo "If you want to change the path, please edit this script."
		echo " "
		pause "Press a touch to begin (or ctrl+c to cancel the installation)..."
		echo " "
		cp ./html2txt2tags ${INSTALLPATH}
	;;
	release)
		cd ..
		zip -r HTML-WikiConverter-Txt2tags.zip ./HTML-WikiConverter-Txt2tags
		echo "Release version is ../HTML-WikiConverter-Txt2tags.zip"
	;;
	*)
		echo "\n\n\n" && cat $1 |  html2wiki --dialect Txt2tags 
	;;
esac



