Last active
November 17, 2017 02:38
-
-
Save senderista/1246300 to your computer and use it in GitHub Desktop.
Some ack-style Spotlight search functions
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
BOLD=`echo -e '\033[1m'` | |
BLACK=`echo -e '\033[30m'` | |
RED=`echo -e '\033[31m'` | |
GREEN=`echo -e '\033[32m'` | |
YELLOW=`echo -e '\033[33m'` | |
BLUE=`echo -e '\033[34m'` | |
MAGENTA=`echo -e '\033[35m'` | |
CYAN=`echo -e '\033[36m'` | |
WHITE=`echo -e '\033[37m'` | |
BG_BLACK=`echo -e '\033[40m'` | |
BG_RED=`echo -e '\033[41m'` | |
BG_GREEN=`echo -e '\033[42m'` | |
BG_YELLOW=`echo -e '\033[43m'` | |
BG_BLUE=`echo -e '\033[44m'` | |
BG_VIOLET=`echo -e '\033[45m'` | |
BG_CYAN=`echo -e '\033[46m'` | |
BG_WHITE=`echo -e '\033[47m'` | |
NORMAL=`echo -e '\033[0m'` | |
function spotlightfile() { | |
mdfind -name "$@" | perl -ne "s/\Q($@)/${BOLD}${BG_YELLOW}\$1${NORMAL}/gi; print;"; | |
} | |
function spotlightcontent() { | |
mdfind -0 -interpret "$@" | xargs -0 grep -inH "$@" | perl -ne "(\$file, \$line, \$text) = /(^.*)\:(\d+)\:(.*)$/; print \"\\n${BOLD}${BLUE}\$file${NORMAL}\\n\" if \$file ne \$curfile; \$curfile = \$file; print \"${BOLD}${RED}\$line${NORMAL}\\t\"; \$text =~ s/^\s+//; \$text =~ s/\Q($@)/${BOLD}${BG_YELLOW}\$1${NORMAL}/gi; print \"\$text\\n\""; | |
} | |
function spotlightfile_in_current_dir() { | |
mdfind -onlyin "$PWD" -name "$@" | perl -pe "s/\Q($@)/${BOLD}${BG_YELLOW}\$+${NORMAL}/gi"; | |
} | |
function spotlightcontent_in_current_dir() { | |
mdfind -0 -onlyin "$PWD" -interpret "$@" | xargs -0 grep -inH "$@" | perl -ne "(\$file, \$line, \$text) = /(^.*)\:(\d+)\:(.*)$/; print \"\\n${BOLD}${BLUE}\$file${NORMAL}\\n\" if \$file ne \$curfile; \$curfile = \$file; print \"${BOLD}${RED}\$line${NORMAL}\\t\"; \$text =~ s/^\s+//; \$text =~ s/\Q($@)/${BOLD}${BG_YELLOW}\$1${NORMAL}/gi; print \"\$text\\n\""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment