blob: 722db0a04568b0b7465cb91520780e675a87742f (
plain) (
blame)
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
|
#!/bin/bash
# Rough implementation of a command line Reddit comment viewer.
# It still needs some work.
curl -A "RCV - Reddit Comments Viewer" -s "$1.json" | jq '.[1].data.children[] | recurse(.data.replies.data?.children[]) | .data | "\(.depth):::\(.author):::\(.body)"' | awk -F':::' '
function prefix(n)
{
pre = ""
for (i=1; i<=n; i++) {
pre = pre " "
}
return pre "┃ "
}
{
gsub(/^"/,"")
gsub(/"$/,"")
pre = prefix(int($1))
gsub(/\\n/,"\n" pre)
comment = pre "[" $2 "]:\n" pre $3 "\n"
gsub(/[^\n]{80}/,"&\n" pre, comment)
print comment
}' | less
|