Skip to content

Instantly share code, notes, and snippets.

@sebastiancarlos
Last active July 31, 2023 19:28
Show Gist options
  • Save sebastiancarlos/a708338aae0307ddff2a2a4b1c7c468c to your computer and use it in GitHub Desktop.
Save sebastiancarlos/a708338aae0307ddff2a2a4b1c7c468c to your computer and use it in GitHub Desktop.
poor-mans-ripgrep.sh - ripgrep for those stuck with grep
# 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