Skip to content

Instantly share code, notes, and snippets.

@jakerieger
Created February 26, 2025 04:51
Show Gist options
  • Save jakerieger/231ec94ba95f6994b213689dbb93e893 to your computer and use it in GitHub Desktop.
Save jakerieger/231ec94ba95f6994b213689dbb93e893 to your computer and use it in GitHub Desktop.
source_dirs=(dir1 dir2 dir3)
total=0
root_dir=$(pwd)
for dir in "${source_dirs[@]}"; do
full_dir="$root_dir/$dir"
cd $full_dir
cpp_lines=$(find . -name '*.cpp' | xargs -I {} cat {} | wc -l)
hpp_lines=$(find . -name '*.hpp' | xargs -I {} cat {} | wc -l)
dir_total=$((cpp_lines + hpp_lines))
echo "$full_dir: $dir_total lines"
total=$((total + cpp_lines + hpp_lines))
cd $root_dir
done
echo ""
echo "Total: $total lines"
@jakerieger
Copy link
Author

Simple bash script that will iterate over a list of directories and count up how many lines of code are in the source files with the provided extensions (.cpp and .hpp in this case). Very slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment