Created
May 17, 2009 19:58
-
-
Save jrk/113145 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # The CommandLineFu.com is a great web site to exchange knowledge about shell usage and command line | |
| # magics. But if that is about command line will be to have a command line interface to access this | |
| # knowledge. | |
| # The clfu-seach is the usable proof of concept to think seriously on this idea. | |
| # via http://www.colivre.coop.br/Aurium/CLFUSearch | |
| # This is a Free (as in freedom) Software licenced under the last GPL. | |
| # Se the licence at http://www.gnu.org/licenses/gpl.html | |
| # Copyright (C) 2009 Aurélio A. Heckert <aurium(a)gmail-dot-com> | |
| search="$@" | |
| if test -z "$search"; then | |
| echo " | |
| $(basename $0) - A command line interface to search at commandlinefu.com | |
| Usage: | |
| \$ $(basename $0) <search words> | |
| Example: | |
| \$ $(basename $0) history uniq | |
| Searching... | |
| history | awk '{print \$2}' | sort | uniq -c | sort -rn | head | |
| List of commands you use most often | |
| history|awk '{print \$2}'|awk 'BEGIN {FS=\"|\"} {print \$1}'|sort|uniq -c|sort -r | |
| See most used commands | |
| " | |
| exit 0 | |
| fi | |
| search_file=$( mktemp ) | |
| echo -e "\e[34mSearching...\e[m" | |
| wget --post-data "q=$search" \ | |
| -O $search_file \ | |
| http://www.commandlinefu.com/search/autocomplete 2>/dev/null | |
| echo -e "$( | |
| grep --invert-match '<div class="autocomplete-description">\|<a style\|<\/\?ul>\|<\/\?li>\|[0-9]\+ comments\?)' $search_file | | |
| sed -r ' | |
| s/\\/\\\\/g; | |
| s/<strong>/\\e[1m/g; | |
| s/<\/strong>/\\e[m\\e[32m/g; | |
| s/^\s*<div class="autocomplete-command">(.*)<\/div>\s*$/\\e[32m\1\\e[m/g; | |
| s/^\s*<\/div>\s*$//g; | |
| s/\s*\([0-9]+ votes?,\s*$//g; | |
| s/^\s*//g; | |
| ')" | |
| echo "" | |
| rm $search_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment