Created
January 5, 2024 17:50
-
-
Save atoa/6bb01aa4193c77229f62c98f8b372b21 to your computer and use it in GitHub Desktop.
script to recursively git grep multiple repos in subdirectories
This file contains 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
#!/usr/bin/env sh | |
# | |
# Git grep on multiple repos in descendant directories from cwd | |
set -euo pipefail | |
IFS=$'\n\t' | |
# how many directories to recurse - helps with performance to keep it low | |
# but may miss subdirectories if too low | |
# it can be overriden by setting this variable in the calling shell | |
MAXDEPTH=${MAXDEPTH:-3} | |
find . -maxdepth "$MAXDEPTH" -type d -name .git -print0 | \ | |
xargs -0 -I@@ sh -c \ | |
'cd "@@/.." ; GIT_PAGER="" git grep --color "$@" | sed -e "s#^#${PWD}/#"' \ | |
-- "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment