Created
July 3, 2018 16:49
-
-
Save h4/c73943fe53c97c722cb9befbd4e4b654 to your computer and use it in GitHub Desktop.
Find substring in git bare repos
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
#!/usr/bin/env bash | |
set -e | |
ROOT=$1 | |
PATTERN=$2 | |
walkdir() { | |
CUR_DIR=$1 | |
pushd $CUR_DIR > /dev/null | |
for DIR in $(ls $CUR_DIR) | |
do | |
if [[ "$DIR" == *.git ]] | |
then | |
if ! [[ "$DIR" == *.wiki.git ]] | |
then | |
find_pattern $(realpath "$DIR") | |
fi | |
else | |
walkdir "$(realpath $DIR)" | |
fi | |
done | |
popd > /dev/null | |
} | |
find_pattern() { | |
CUR_REPO=$1 | |
pushd $CUR_REPO > /dev/null | |
exit_code=0 | |
git grep -e "$PATTERN" HEAD 2>/dev/null || exit_code=$? | |
if [ "$exit_code" -eq "0" ] | |
then | |
pwd | |
printf "\n\n" | |
fi | |
popd > /dev/null | |
} | |
walkdir "$ROOT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment