Skip to content

Instantly share code, notes, and snippets.

@cristianobecker
Last active December 30, 2016 04:24
Show Gist options
  • Save cristianobecker/72b2ec4196ef675e88ab to your computer and use it in GitHub Desktop.
Save cristianobecker/72b2ec4196ef675e88ab to your computer and use it in GitHub Desktop.
Fast way to search in files in small projects
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