Page 1 of 1

View XKCD from a terminal.

Posted: Mon Jul 03, 2017 5:50 pm UTC
by kbenoit
I don't know why I wanted read XKCD without going to the browser. I thought it was a nice thing to do it in a single line. Then I thought I should share it.

So here's my one line command to read XKCD from bash.

Code: Select all

wget https://xkcd.com/ -O - 2> /dev/null | sed -n -e 's/.*\(\/\/imgs.xkcd.com\/comics\/[^ "]*\).*/https:\1/gp' | head -n 1 | xargs eog


We could also set an alias:

Code: Select all

alias xkcd="wget https://xkcd.com/ -O - 2> /dev/null | sed -n -e 's/.*\(\/\/imgs.xkcd.com\/comics\/[^ \"]*\).*/https:\1/gp' | head -n 1 | xargs eog"


Kristian

Re: View XKCD from a terminal.

Posted: Wed Jul 05, 2017 10:24 am UTC
by hotaru
you should use the json interface instead of trying to parse HTML with sed.

Re: View XKCD from a terminal.

Posted: Wed Aug 30, 2017 10:17 pm UTC
by Jplus
Also, there is xkcd-fetch (which wraps the JSON interface).

Re: View XKCD from a terminal.

Posted: Wed Aug 30, 2017 11:59 pm UTC
by commodorejohn
Well it's hardly "from a terminal" if you're just launching a graphical image viewer! What we really need here...is there a convenient command-line interface for something like aalib?

Re: View XKCD from a terminal.

Posted: Sat Sep 02, 2017 10:45 am UTC
by Tub
hotaru wrote:you should use the json interface instead of trying to parse HTML with sed.

Yes. Parsing json with sed is the superior solution.
commodorejohn wrote:is there a convenient command-line interface for something like aalib?

aview is an image viewer using aalib, but I doubt the results will be readable. Unless you have a very large terminal.

Re: View XKCD from a terminal.

Posted: Mon Sep 04, 2017 1:20 am UTC
by phlip
Clearly the obvious solution to that is to combine aalib with some sort of OCR, so that text in the original comic comes out as readable text in the terminal, but the drawings in the comic get the normal aalib treatment.

I'm sure such a plan will be simple and have no possible drawbacks.