#!/bin/sh -e

if [ -z "$1" ]; then
	thought=$(cat -)
elif [ -f "$1" ]; then
	thought=$(cat "$1")
else
	thought="$*"
fi

thought="$(printf "%s" "${thought}" | sed '{s#^#\\t\\t\\t\\t\\t#;s#^\\t\\t\\t\\t\\t$#\\t\\t\\t\\t</p>\\\n\\t\\t\\t\\t<p>#;s#$#\\#;}')"
# thought="$(echo -n "${thought}" | sed '{s/$$/<\/p>\n<p>/;s/$/\\/;s/^/\\t\\t\\t\\t\\t/;};${s/<br>\\$/\\/;p;x;};1d')"
date=$(date '+%a, %d %b %Y %H:%M')
html_fmt='\t\t\t\t<h3>'"${date}"'</h3>\
\t\t\t\t<p>\
'"${thought}"'
\t\t\t\t</p>\
'
case $(hostname -s) in
	mother|po-rbo) sed="sed -i" ;;
	mars) sed="sed -i ''" ;;
esac

$sed -e '/<!-- thoughts here -->$/{n;s#^#'"${html_fmt}"'#;}' \
	"$HOME"/dev/web/joe-www/thoughts.html
git -C "$HOME"/dev/web/joe-www add -u
git -C "$HOME"/dev/web/joe-www commit -m "Thought: ${date}"
git -C "$HOME"/dev/web/joe-www push

vps