Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A bash script that counts go function and method lines of code (including whitespace and comments)
# Usage: bash some/directory
set -euo pipefail
main() {
for f in $(find $1 -name '*.go' -not -name 'test_*.go'); do
count_funcs < "$f" | awk "{ print \"$f\", \$1, \$2 }"
count_funcs() {
ruby -e '^func\s*(?:\([^)]+\))?\s*(\w+)\(.+?^})/m) {|whole, name| puts("#{name}\t#{whole.scan(/\n/).length}")}; nil'
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.