View the newest xkcd comic.

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 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 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}\';}

\"\"

by David Winterbottom (codeinthehole.com)

\"\"
\"\"

\"\"

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/JtqAcfWoFMA/view-the-newest-xkcd-comic.