Display the history and optionally grep

Ever wondered how good it would be to have a command/function that would display the history or display the history with grep.

Would be really good right, well someone thought about this 🙂

$ h() { if [ -z \”$1\” ]; then history; else history | grep \”[email protected]\”; fi; }

Place this in your .bash_profile and you can use it two different ways. If you issue \’h\’ on its own, then it acts like the history command. If you issue:

h cd

Then it will display all the history with the word \’cd\’

* View this command to comment, vote or add to favourites * View all commands by haivu

commandlinefu.com

by David Winterbottom (codeinthehole.com)

URL: http://feedproxy.google.com/~r/Command-line-fu/~3/M_TyUNnb_IA/display-the-history-and-optionally-grep

\"Reblog

Display a block of text with delineated by a start pattern and an end pattern

Taken idea from commandlinefu.com

The command will display a segment from the file from the start pattern to the end pattern.

function viewsegment() { tail -n +`fgrep -n -m 1 "$1" $3 | head -`fgrep -n -m 1 "$2" $3 }
Display a block of text with delineated by a start pattern and an end pattern

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.