#!/bin/sh

yargle=`sh -c "echo -n foo" | grep -e -n`
if [ -n "$yargle" ]; then
Echo="echo"	# ksh
NoNL="\\c"
else
Echo="echo -n"	# bash or ash
NoNL=""
fi

echo "Configuring note for your setup."
echo

$Echo "Which note? (one of ansi, iv, mono) [ansi] $NoNL"
read yargle
if [ "$yargle" = "iv" ]; then
Main=iv
elif [ "$yargle" = "mono" ]; then
Main=mono
else
Main=ansi
fi

cat src/head.$Main > note
echo >> note

if [ $Main = mono ]; then
echo "The position function won't work with the mono note"
else
$Echo "Use the position function? [y] $NoNL"
read yargle
if [ "$yargle" = "y" -o "$yargle" = "" ]; then
echo "UsePosition=1" >> note
else
echo "# UsePosition=1" >> note
fi
echo >> note
fi

$Echo "Editor command? [pico -t] $NoNL"
read yargle
if [ -z "$yargle" ]; then
Edit="pico -t"
else
Edit="$yargle"
fi
echo 'if [ -n "$EDITOR" ]; then' >> note
echo 'Edit=$EDITOR' >> note
echo "else" >> note
echo "Edit=\"$Edit\"" >> note
echo "fi" >> note
echo >> note

cat src/main.$Main >> note

chmod 755 note
echo
echo "Done."

