#!/bin/bash
if [ -z "$1" ]; then 
	echo "$0 <Filename / part of to remove>"
	exit
fi

echo "---------------------"
grep $1 *.mxml sp-with-simplesign
echo "---------------------"
echo -n "OK to remove ? [Y/n]"
read x
case $x in 
	"Y"|"y"|"") ;;
	 *) exit 1 ;;
esac

echo
if [ `uname -s` == "Darwin" ]; then
	MacOSX=true
else
	MacOSX=false
fi
if (grep -q $1 sp-with-simplesign); then
	if ( $MacOSX ) ; then
		sed -i "" "/$1/d" sp-with-simplesign
	else
		sed -i "/$1/d" sp-with-simplesign
	fi
fi
grep $1 *.mxml | sed 's/.*:  <xi:include href="\(.*\)"\/>/\1/' | while read file ; do
	git rm $file
done

grep $1 *.mxml | sed 's/\(.*\.mxml\):  <xi:include href=".*"\/>/\1/' | while read file ; do
	if ( $MacOSX ) ; then
		sed -i "" "/$1/d" $file
	else
		sed -i "/$1/d" $file
	fi
done
git diff