View the newest xkcd comic.

2009-12-07 129 words 1 min read

This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic.

$ xkcd(){ local f=$(curl -s <a href="http://xkcd.com/">http://xkcd.com/);display $(echo "$f"|grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)');echo "$f"|awk '/<img src="http://imgs.xkcd.com/comics/.?" title=./{gsub(/^.title=.|".?$/,"");print}';}

To get a random xkcd comic, I also use the following:

xkcdrandom(){ local f=$(wget -q <a href="http://dynamic.xkcd.com/comic/random/">http://dynamic.xkcd.com/comic/random/ -O -);display $(echo "$f"|grep -Po '(?<=")http://imgs.xkcd.com/comics/[^"]+(png|jpg)');echo "$f"|awk '/<img src="http://imgs.xkcd.com/comics/.?" title=./{gsub(/^.title=.|".?$/,"");print}';}

  • <a href="http://www.commandlinefu.com/commands/view/4167/view-the-newest-xkcd-comic.">View this command to comment, vote or add to favourites
  • <a href="http://feeds2.feedburner.com/commands/by/eightmillion">View all commands by <a href="http://feeds2.feedburner.com/commands/by/eightmillion">eightmillion

<a href="http://www.commandlinefu.com"><img src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/header-logo.jpg" alt="" align="bottom" />

by David Winterbottom (<a href="http://codeinthehole.com">codeinthehole.com)

<a href="http://feedads.g.doubleclick.net/~a/_wgpy7hJ2JNzPI94n9ZmFYZrVoU/0/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/_wgpy7hJ2JNzPI94n9ZmFYZrVoU/0/di" alt="" align="bottom" />
<a href="http://feedads.g.doubleclick.net/~a/_wgpy7hJ2JNzPI94n9ZmFYZrVoU/1/da"><img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~a/_wgpy7hJ2JNzPI94n9ZmFYZrVoU/1/di" alt="" align="bottom" />

<img src="http://blog.amit-agarwal.com/wp-content/uploads/img.zemanta.com/~r/Command-line-fu/~4/JtqAcfWoFMA" alt="" width="1" height="1" align="bottom" />

URL: <a href="http://feedproxy.google.com/~r/Command-line-fu/~3/JtqAcfWoFMA/view-the-newest-xkcd-comic.">http://feedproxy.google.com/~r/Command-line-fu/~3/JtqAcfWoFMA/view-the-newest-xkcd-comic.


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it