Created
February 3, 2012 05:28
-
-
Save javier-lopez/1728310 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
| #!/usr/bin/env bash | |
| #chilicuil <chilicuil@gmail.com> 2010 | |
| #search in the awesome www.commandlinefu.com site | |
| PATTERN="$@" | |
| # I love colors! | |
| BLUE=$'\E[0;34m' | |
| DEFAULT=$'\E[0m' | |
| RED=$'\E[0;31m' | |
| BROWN=$'\E[0;33m' | |
| CYAN=$'\E[0;36m' | |
| DARK_GREY=$'\E[1;30m' | |
| GREEN=$'\E[0;32m' | |
| LIGHT_BLUE=$'\E[1;34m' | |
| LIGHT_CYAN=$'\E[1;36m' | |
| LIGHT_GREEN=$'\E[1;32m' | |
| LIGHT_GREY=$'\E[0;37m' | |
| LIGHT_PURPLE=$'\E[1;35m' | |
| LIGHT_RED=$'\E[1;31m' | |
| PURPLE=$'\E[1;35m' | |
| WHITE=$'\E[1;37m' | |
| YELLOW=$'\E[0;33m' | |
| usage() | |
| { | |
| echo "Usage: `basename $0` [-c] pattern" >&2 | |
| echo >&2 | |
| echo " -c Colorize the output" >&2 | |
| exit 1 | |
| } | |
| if [[ -z "$PATTERN" ]]; then | |
| usage | |
| fi | |
| while getopts ":c:" option; do | |
| case $option in | |
| c) | |
| CFLAG=yes PATTERN=$OPTARG ;; | |
| :) | |
| echo "Option -$OPTARG requires an argument" | |
| usage | |
| ;; | |
| \?) | |
| echo "Invalid option: -$OPTARG" | |
| usage | |
| ;; | |
| esac | |
| done | |
| if [[ -z $CFLAG ]]; then | |
| curl -s "http://www.commandlinefu.com/commands/matching/$PATTERN/`echo -n $PATTERN | base64`/plaintext/sort-by-votes" |\ | |
| grep --invert-match "commandlinefu.com by David Winterbottom" #I wanna keep the output as clean as possible | |
| else | |
| curl -s "http://www.commandlinefu.com/commands/matching/$PATTERN/`echo -n $PATTERN | base64`/plaintext/sort-by-votes" |\ | |
| grep --invert-match "commandlinefu.com by David Winterbottom" | sed -e " | |
| s:^#.*:$PURPLE&$DEFAULT:g" -e " | |
| s:[^#].*:$LIGHT_GREEN&$DEFAULT:g" -e " | |
| /#/!s/\<$PATTERN\>/$YELLOW&$LIGHT_GREEN/g" #for some reason if I change / for : it doesn't work | |
| # I couldn't find any way to run :#:!s:\<$PATTERN\>/$RED&$LIGHT_GREEN\$/g in only 1 sed, actually I could ^-^ | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment