I love http://commandlinefu.com. While doing my once-a-week search for interesting command-line chops the other day I discovered they have a simple search API. I thought it would be useful to integrate this into my bash shell so I could quickly pull up examples of useful linux commands.
Here is what I came up with. Basically I bind ctrl-u in bash to prompt me for a search term, then I use curl to search commandlinefu.com via their plaintext API.
Here is what I came up with. Basically I bind ctrl-u in bash to prompt me for a search term, then I use curl to search commandlinefu.com via their plaintext API.
Paste this into your .bash_profile
function doCLFSearch { echo -n "search http://commandlinefu.com for: " read SEARCHTERM URL_ENC_ST=`php -r "echo rawurlencode('$SEARCHTERM');"` ENCODED=`echo -n $SEARCHTERM | openssl enc -base64` curl -s "http://www.commandlinefu.com/commands/matching/$URL_ENC_ST/$ENCODED/plaintext" | less -p "$SEARCHTERM" }
bind '"\C-u"':"\"doCLFSearch\C-m\""
source .bash_profile
Then hit ctrl-u and search away!
Enjoy.
CP