#!/bin/sh
# Usage: format-irclog.sh <file>
# 1. Append two spaces to the end of each line.
# 2. Remove all characters before last `<`, e.g. `<matterbridge> <sgp> foo` becomes `<sgp> foo`.
# 3. Remove lines containing `⇐` (parts).
# 4. Remove lines containing `→` (joins).
# 5. Remove lines containing only whitespace.
# 6. Escape the `*` character, e.g. `*foo*` becomes `\*foo\*`.
# 7. Escape the `<` character, e.g. `<3` becomes `\<3`.
# 8. Escape the `>` character, e.g. `1 > 0` becomes `1 \> 0`.
# 9. Embolden nick, e.g. `\<sgp\> foo` becomes `**\<sgp\>** foo`.
sed -E \
-e 's/$/\ \ /' \
-e 's/.*</</' \
-e '/⇐/d' \
-e '/→/d' \
-e '/^[[:space:]]*$/d' \
-e 's/\*/\\\*/g' \
-e 's/_/\\_/g' \
-e 's/</\\</g' \
-e 's/>/\\>/g' \
-e 's/\\<([^ ]+)\\>/\*\*\\<\1\\>\*\*/' \
$1