Skip to content

Instantly share code, notes, and snippets.

@rebx
Last active December 15, 2015 06:38
Show Gist options
  • Save rebx/5217248 to your computer and use it in GitHub Desktop.
Save rebx/5217248 to your computer and use it in GitHub Desktop.
Quick unused subroutine finder using ack(http://betterthangrep.com) + git
#!/bin/bash
dir=$1
if [ -z "$dir" -a "${dir+oinothir}" = "oinothir" ]; then
dir=$PWD
fi
ack -h --output='$1' '^\s*sub\s+(\w+)\b' $dir \
| sort -u \
| while read subname ; do
export subname
git grep -c -w -F "$subname" \
| awk -F: '{t+=$2} END{if(t<2) print ENVIRON["subname"]}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment