blob: 086d5380a02acaa92a95cf7219aef479a7f86d84 (
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
|
#!/bin/bash
## Please do not judge me, i don't even like reddit, it just had the easiest API
API_URL="https://api.reddit.com/best"
if [[ "$1" = "--help" ]]; then
cat >&2 <<-"EOF"
Usage: $0 [subreddit]
Specifying a subreddit is optional, and should be done without r/ prefix
EOF
exit 1
elif [[ -n "$1" ]]; then
API_URL="https://api.reddit.com/r/$1/best"
fi
QUAD=$(
curl -H "User-Agent: bash:moe.nea89.meme-tui" "$API_URL" 2>/dev/null | jq -r ".data.children[].data | select(.post_hint == \"image\") | .url,.title,.id,.subreddit_name_prefixed" | head -n 4
echo x
)
QUAD=${QUAD%?}
{ read -r image && read -r title && read -r id && read -r subreddit; } < <(echo "$QUAD")
curl -L "$image" 2>/dev/null | ./osc showimg
echo
./osc anchor "https://redd.it/$id" "$title"
printf " "
./osc anchor "https://reddit.com/$subreddit" "($subreddit)"
echo
|