Last active
July 31, 2023 19:28
-
-
Save sebastiancarlos/a708338aae0307ddff2a2a4b1c7c468c to your computer and use it in GitHub Desktop.
poor-mans-ripgrep.sh - ripgrep for those stuck with grep
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
# All my gist code is licensed under the terms of the MIT license. | |
# poor-man's ripgrep | |
# - like grep, but ignore hidden files and folders (prefixed with a dot) and | |
# node_modules. | |
# - because grep's --exclude-dir only matches top-level directories, we need to | |
# use find | |
# - last argument is starting point. It must be provided, otherwise it's tricky | |
# to distinguish it from the pattern | |
# - any previous arguments are passed to grep before the matching files, | |
# assuming they are patterns and options | |
function poor-mans-ripgrep () { | |
if [[ "$#" -lt 2 ]]; then | |
echo "usage: poor-mans-ripgrep [grep options] pattern starting_point" | |
return 1 | |
fi | |
local starting_point="${@: -1}" | |
find "$starting_point" \ | |
-not -path '*/\.*' \ | |
-not -path '*/node_modules/*' \ | |
-type f \ | |
-exec grep -E --color=auto --binary-files=without-match "${@:1:$#-1}" '{}' + | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment