#!/bin/sh -e
title="untitled"
if [ -z "$2" ]; then
	thought=$(cat -)
	title="$1"
elif [ -f "$2" ]; then
	thought=$(cat "$2")
	title="$1"
else
	thought="${*:2}"
	title="$1"
fi
thought="$(printf "%s" "${thought}" | sed '{s#^#\\t\\t\\t\\t\\t#;s#^\\t\\t\\t\\t\\t$#\\t\\t\\t\\t
\\\n\\t\\t\\t\\t#;s#$#\\#;}')"
date=$(date '+%a, %d %b %Y %H:%M')
html_fmt='\t\t\t\t
'"${title}"'
\
\t\t\t\t'"${date}"'
\
\t\t\t\t\
'"${thought}"'
\t\t\t\t
\
'
rss_fmt='\\t- \
\t\t'"${title}"'\
\t\t'"${date} $(date '+%Z')"'\
\t\tjoe
\t\t'"$(uuidgen)"'\
\t\t\
\t\t\t'"${thought}"'
\t\t\
\t'
case $(hostname -s) in
	mother|po-rbo) sed="sed -i" ;;
	mars) sed="sed -i ''" ;;
esac
$sed -e '/<\/channel>/i '"${rss_fmt}" \
	"$HOME"/dev/web/joe-www/thoughts.xml
$sed -e '/$/{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