From d9031203e22e4ef381c482b4594521323647487e Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 13 Jan 2022 00:01:56 +0100 Subject: Initial commit --- reddit | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 reddit (limited to 'reddit') diff --git a/reddit b/reddit new file mode 100755 index 0000000..086d538 --- /dev/null +++ b/reddit @@ -0,0 +1,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 -- cgit