add simple xkcd comic browser

This commit is contained in:
randomuser 2021-05-15 21:10:31 -05:00
parent 2ea5dbd49f
commit 8d22255c0e
1 changed files with 40 additions and 0 deletions

40
scripts/xkcd Executable file
View File

@ -0,0 +1,40 @@
#!/bin/sh
set -x
err () {
printf "err: %s\n" ${1}
[ -z "${2}" ] && exit 1
exit ${2}
}
getImageForComic() {
[ -z ${1} ] && a="" || a="$1/"
curl --silent https://xkcd.com/${a} | grep 'imgs.xkcd.com/comics/' | sed 1q | grep -o 'https://imgs\.xkcd\.com/comics/.*\....'
}
viewImage() {
a=$(mktemp)
curl --silent $(getImageForComic ${1}) -o $a
feh $a
}
proghelp() {
printf "\
xkcd - view xkcd comics
=> [v]iew [id] - View comic with id [id]
=> [g]et [id] - Get url for comic [id]
"
}
case $1 in
'v'*)
viewImage $2
exit 0
;;
'g'*)
getImageForComic $2
exit 0
;;
*)
proghelp
exit 0
;;
esac
exit 0