Skip to content

Instantly share code, notes, and snippets.

@00-matt
Last active July 10, 2020 13:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save 00-matt/3147fca586ba4270cb77877c9a798a8b to your computer and use it in GitHub Desktop.
Save 00-matt/3147fca586ba4270cb77877c9a798a8b to your computer and use it in GitHub Desktop.
#!/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. Escape the `*` character, e.g. `*foo*` becomes `\*foo\*`.
# 6. Escape the `<` character, e.g. `<3` becomes `\<3`.
# 7. Escape the `>` character, e.g. `1 > 0` becomes `1 \> 0`.
# 8. Embolden nick, e.g. `\<sgp\> foo` becomes `**\<sgp\>** foo`.
sed -E \
-e 's/$/\ \ /' \
-e 's/.*</</' \
-e '/⇐/d' \
-e '/→/d' \
-e 's/\*/\\\*/g' \
-e 's/_/\\_/g' \
-e 's/</\\</g' \
-e 's/>/\\>/g' \
-e 's/\\<([^ ]+)\\>/\*\*\\<\1\\>\*\*/' \
$1
#!/bin/sh
if [ "$#" -ne 5 ]; then
echo "Usage: $0 <YYYY> <MM> <DD> <CHAN> <TITLE>" >&2
echo "Example: $0 2020 06 06 monero-community Community" >&2
exit 1
fi
AUTHOR=asymptotically
YYYY="$1"
MM="$2"
DD="$3"
CHAN="$4"
TITLE="$5"
FN="_posts/${YYYY}-${MM}-${DD}-${CHAN}-meeting.md"
REMOTE="https://monerologs.net/${CHAN}/${YYYY}${MM}${DD}/raw"
cat <<EOF>"$FN"
---
layout: post
title: Logs for the ${TITLE} Meeting Held on ${YYYY}-${MM}-${DD}
author: ${AUTHOR} / TODO
---
# Logs
EOF
curl -s "$REMOTE" |
sed -E \
-e 's/$/\ \ /' \
-e 's/.*</</' \
-e 's/\*/\\\*/g' \
-e 's/_/\\_/g' \
-e 's/</\\</g' \
-e 's/>/\\>/g' \
-e 's/\\<([^ ]+)\\>/\*\*\\<\1\\>\*\*/' >>"$FN"
"$EDITOR" "$FN"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment