Last active
December 30, 2016 04:24
-
-
Save cristianobecker/72b2ec4196ef675e88ab to your computer and use it in GitHub Desktop.
Fast way to search in files in small projects
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
search-files() { | |
local folder=$(test $# -eq 2 && echo "$1" || echo .) | |
local query=$(test $# -eq 2 && echo "$2" || echo "$1") | |
local IFS=$'\n' | |
for f in $(find "$folder" -type f); do | |
local result=$( | |
cat "$f" | | |
GREP_COLOR='01;32' egrep --color=always -n "$query" | | |
GREP_COLOR='01;33' egrep --color=always "^\d+:" | |
) | |
test "x$result" != x && printf "\e[1m$f\e[0m:\n$result\n\n" | |
done | |
} | |
# Usage: | |
# search-files resources/assets/js setInterval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment