summaryrefslogtreecommitdiff
path: root/show-irc-log
blob: 0986b21dec4e8db7120fd0fc0fd1b8e843e29c21 (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
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash

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

curl -Ss 'https://mirror.archlinux32.org/irc-logs/%23archlinux32/' \
| sed '
  s@^<a href="\([-0-9]\+\)\.html">\1</a>$@\1@
  t
  d
' \
| sort -r \
| {
  lines_count=0
  while read -r s; do
    lines=$(
      curl -Ss 'https://mirror.archlinux32.org/irc-logs/%23archlinux32/'"${s}"'.html' \
      | 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
      ' \
      | tac
    )
    if [ -z "${lines}" ]; then
      continue;
    fi
    lines_count=$((lines_count + $(printf '%s\n' "${lines}" | wc -l)))
    printf '%s\n' "${lines}"
    if [ "${lines_count}" -ge 30 ]; then
      cat >/dev/null
      break
    fi
  done
} \
| tac \
| 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[^|]\{'"$((cols-2))"'\}[|:]/b
          s/[|:]/ \0/
          ba
      '
  } | \
  tail -n30 | \
  tac