summaryrefslogtreecommitdiff
path: root/show-irc-log
blob: 185417c83191e77cbd0eb80361c3d5c70b5bb07a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

tmp_dir=$(mktemp -d)
trap 'rm -rf --one-file-system "${tmp_dir}"' EXIT

if ! mountpoint -q /mnt/archlinux32; then
  sleep $(($RANDOM%20))
  if ! mountpoint -q /mnt/archlinux32; then
    mount /mnt/archlinux32 || \
      exit
  fi
fi

find /mnt/archlinux32/irc-logs/#archlinux-ports/ \
  -type f \
  -mtime -2 \
  -name '*-*-*.html' | \
  sort | \
  while read -r s; do
    sed -n '
      s|^.* <span class="person" style="[^"]\+">&lt;\([^&]\+\)&gt;</span>|\1 \||
      t ok
      s|^.* <span class="person" style="[^"]\+">\* \(\S\+\) \(.*\)</span>.*$|\1 : \2|
      t ok
      T
      :ok
      p
    ' "${s}"
  done | \
  tail -n30 > \
  "${tmp_dir}/input"

sed -n '
  s@[|:].*$@|@
  T
  p
' "${tmp_dir}/input" | \
  {
    cols=0
    while read -r s; do
      if [ ${#s} -gt ${cols} ]; then
        cols=${#s}
      fi
    done

    sed '
      s@\(\([|:]\).\{'"$((50-cols))"'\}\)\(.\)@\1\n\2 \3@
      P
      D
    ' "${tmp_dir}/input" | \
      sed '
        s/^[^|:]*$/| \0/
        :a
          /^.\{'"$((cols-1))"'\}[|:]/b
          s/[|:]/ \0/
          ba
      '
  } | \
  tail -n30 | \
  tac