Skip to content

Instantly share code, notes, and snippets.

@hwms
Created July 9, 2015 11:00
Show Gist options
  • Save hwms/1ea10c16683e33da0761 to your computer and use it in GitHub Desktop.
Save hwms/1ea10c16683e33da0761 to your computer and use it in GitHub Desktop.
Find unused class and def definitions in python code
#!/bin/bash
for F in "$@"; do
DEFS=`grep -E '^ *def|^ *class' ${F} | sed -e 's/^ *//g' | cut -d ' ' -f 2 | cut -d '(' -f 1 | cut -d ':' -f 1 | sort | sed ':a;N;$!ba;s/\n/\n/g' | uniq`
#echo $DEFS
for D in $DEFS; do
COUNT=`grep -rn $D | wc -l`
#echo $D $COUNT
if [ $COUNT -eq 1 ]; then
grep -rn $D
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment