Created
July 31, 2012 00:49
-
-
Save thibaudcolas/3212355 to your computer and use it in GitHub Desktop.
Callfinder
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 bash | |
# | |
# Callfinder is a really dumb tool that helps you | |
# find if/where functions/classes/variables are used. | |
# It uses grep to find occurences of given strings. | |
# @author ThibWeb | |
# | |
# Usage : ./callfinder.sh FILE THRESHOLD | |
# FILE is the path to a file where each line is a function to search for. | |
# Ex : grep my/js/file.js 'function' > function-file.txt | |
# Threshold allows you to select what to display. | |
if [[ $# == 1 ]]; then | |
FILE=$1 | |
else | |
# Default list file. | |
FILE=callfinder.txt | |
fi | |
if [[ $# == 2 ]]; then | |
THRESHOLD=$2 | |
else | |
# Default threshold : only show unused functions. | |
THRESHOLD=1 | |
fi | |
while read line; do | |
count=`grep -n --color -r $line * --exclude $FILE | wc -l` | |
echo "-------------------------------------------------------------------------------" | |
echo "|" $count " > " $line | |
if (($count <= $THRESHOLD)); then | |
echo "|" | |
grep -n --color -r $line * --exclude $FILE | |
fi | |
done < $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment