Display the history and optionally grep

2010-05-19 1 min read bash
Ever wondered how good it would be to have a command/function that would display the history or display the history with <a class="zem_slink" title="Grep" rel="wikipedia" href="http://en.wikipedia.org/wiki/Grep">grep. Would be really good right, well someone thought about this 🙂 $ h() { if [ -z &#8221;$1&#8221; ]; then history; else history | grep &#8221;$@&#8221;; fi; } Place this in your .bash_profile and you can use it two different ways. If you issue &#8217;h&#8217; on its own, then it acts like the history command. Continue reading

View the newest xkcd comic.

2009-12-07 1 min read bash Linux
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 '(? Continue reading