Skip to content

Instantly share code, notes, and snippets.

@paulroth3d
Created May 11, 2018 06:23
Show Gist options
  • Save paulroth3d/b30c2603dd9b22485e6db9a595304c7d to your computer and use it in GitHub Desktop.
Save paulroth3d/b30c2603dd9b22485e6db9a595304c7d to your computer and use it in GitHub Desktop.
Find Dev usage
#!/bin/bash
# @TODO: provide more documentation.
# This is a shellscript that works on *nix / mac - but does not work on windows
# because it needs to use grep (and the very important -c --context lines around those matches
# but can be used on windows with a *nix emulator like cygwin
# to run: . findDevUsage.sh "[[ Field API Name to search ]]"
# this will output a file in /tmp/fieldAssignments/fieldAPIName__c_usage.html"
# or
# . findDevUsage.sh
# (note the period)
# and it will prompt you what to search
# require aha to highlight matches in results, as otherwise it may not be clear.
type aha >/dev/null 2>&1 || { echo >&2 "I require aha to highlight matches, but cannot find it. Please run 'brew install aha' before continuing."; return; }
# how many lines above and below a match to include
# (so we can get context around the match)
contextSize=5
# ask the end user what term to search (if the argument was not sent)
if [ -z "${1}" ]; then
echo "What should I search for in custom development?"
read search
else
search="${1}"
fi
mkdir -p /tmp/fieldAssignments
filePath="/tmp/fieldAssignments/${search}_usage.html"
# grep to search the current directory for files that include the code to search for | highlight matches with a color > put the results in /tmp/fieldAssignments/YourFieldName_usage.html
grep -r -n -i -C ${contextSize} --color=always --exclude \*.layout --exclude \*_Test.cls --exclude \*.profile --exclude gbc_\*_js.js --exclude \*.resource --exclude \*.permissionset "${search}" . | aha --title "${search} used" --line-fix --black > "${filePath}"
# open the resulting file.
open "${filePath}"
#!/bin/bash
# to call run
# . findDevUsages.sh "[[ Field API Name to search ]]" "[[ Field API Name to search ]]" "[[ Field API Name to search ]]"
for search in "$@"
do
echo "searching for: ${search}"
. findDevUsage.sh "${search}"
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment