Skip to content

Instantly share code, notes, and snippets.

@sbassett29
Last active February 26, 2021 22:08
Show Gist options
  • Save sbassett29/f99f0926843496c92bd127b0c40297d1 to your computer and use it in GitHub Desktop.
Save sbassett29/f99f0926843496c92bd127b0c40297d1 to your computer and use it in GitHub Desktop.
Opinionated code line count tool for Wikimedia code repo dirs
#!/usr/bin/env bash
################################################################################
# Author: [email protected]
# License: Apache 2 <https://opensource.org/licenses/Apache-2.0>
# Description:
# Opinionated code line count tool for code repo dirs
################################################################################
set -euo pipefail
# vars
readonly debug=0
readonly find_cmd='/usr/bin/find '
readonly line_count_cmd=' | xargs cat | wc -l '
code_dir='. '
file_types='-type f '
not_paths=\
'-not -path "*./.git*" '\
'-not -path "./.phan/*" '\
'-not -path "./package-lock.json" '\
'-not -path ".composer.lock" '
# process opts
for opt in "$@"; do
case "$opt" in
# Option: --path={path}
--path=*)
code_dir="${opt#*=}"
;;
# Option: --exts={.ext1,.ext2,.ext3}
--exts=*)
ext_types="${opt#*=}"
or=''
file_types="$file_types\("
for i in ${ext_types//,/ }
do file_types="$file_types$or -name \"*$i\" "
or='-o'
done
file_types="$file_types\)"
;;
*)
printf "unknown option: $opt\n" 1>&2
printf "usage: script_name [--path={path}] [--exts={.ext1,.ext2,.ext3}]\n" 1>&2
exit 1
;;
esac
done
# eval command
cmd="$find_cmd $code_dir $file_types $not_paths $line_count_cmd"
if [ $debug == 1 ]; then
printf "$cmd\n"
else
eval $cmd
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment