Skip to content

Instantly share code, notes, and snippets.

@timruffles
Created June 12, 2020 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timruffles/eec75d0784245283fe52dfe419d21eb5 to your computer and use it in GitHub Desktop.
Save timruffles/eec75d0784245283fe52dfe419d21eb5 to your computer and use it in GitHub Desktop.
A bash script that counts go function and method lines of code (including whitespace and comments)
#!/bin/bash
#
# Usage: bash count_functions_loc.sh 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 }"
done
}
count_funcs() {
ruby -e 'STDIN.read.scan(/(^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