Dotfiles/bin/.bin/xkcd
Jonathan Hodgson 0d357e8f9e Makes linkhandler handle more
It now handles some peertube, more invidious and xkcd
2020-09-19 11:12:34 +01:00

18 lines
622 B
Bash
Executable file

#!/usr/bin/bash
comic=$1
if [[ "$comic" == "" ]]; then
json=$(curl https://xkcd.com/info.0.json 2> /dev/null)
elif [[ "$comic" == "random" ]] || [[ "$comic" == "r" ]]; then
latest=$(curl https://xkcd.com/info.0.json 2> /dev/null | /usr/bin/jq ".num")
number=$(shuf -i1-$latest -n1)
json=$(curl https://xkcd.com/$number/info.0.json 2> /dev/null)
else
if [[ "$comic" = *"xkcd.com"* ]]; then
json=$(curl $comic/info.0.json 2> /dev/null)
else
json=$(curl https://xkcd.com/$comic/info.0.json 2> /dev/null)
fi
fi
echo $json | /usr/bin/jq -C
echo $json | /usr/bin/jq ".img" | xargs curl -s -o /tmp/xkcd
sxiv /tmp/xkcd