-
-
Save kamend/9173683 to your computer and use it in GitHub Desktop.
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
#! /bin/bash | |
# | |
# simple script to check for a given string pattern in any | |
# .c, .h, .cpp, .cxx, .m, & .mm source files | |
# | |
# Dan Wilcox <[email protected]> 2014 | |
# | |
# super simple command parsing | |
if [ $# -lt 1 -o "$1" == "-h" -o "$1" == "--help" ] ; then | |
echo "Usage: check-for-src-pattern \"pattern to match\"" | |
exit 0 | |
fi | |
PATTERN="$1" | |
echo "Checking for \"$PATTERN\" ..." | |
echo "" | |
# set internal field separator to endline so filenames with spaces are not broken up | |
IFS=$'\n' | |
# get a list of source files in the given dir | |
files=$(find . -type file \( -name *.c -o -name *.h -o -name *.cpp -o -name *.cxx -name *.m -o -name *.mm \)) | |
for file in ${files[*]} ; do | |
# check against the given pattern, print the filename and grep output if we find a match | |
found=$(grep -n "$PATTERN" "$file") | |
if [ "$found" != "" ] ; then | |
echo "$file:" | |
echo $found | |
echo "" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment