Line Count

Number of lines in a (python + js) codebase:

#!/bin/zsh

# This script counts the number of non-blank lines of code in a directory and its subdirectories
# for Python and JavaScript code only

# Set the directory to search for code files
dir='.'

# Count the number of non-blank lines of code for Python and JavaScript files
num_lines=$(find "$dir" -type f \( -name '*.py' -or -name '*.js' \) -not -path '*venv*' -not -path '*node_modules*' -exec grep -he '^[^[:space:]]' {} + | awk 'NF{count++} END{print count}')

echo "Number of non-blank lines of code: $num_lines"

Number of lines per-file in a (python + js) codebase:

#!/bin/zsh

# This script counts the number of non-blank lines of code in a directory and its subdirectories
# for Python and JavaScript code only

# Set the directory to search for code files
dir='.'

# Count the number of non-blank lines of code for Python and JavaScript files
num_lines=$(find "$dir" -type f \( -name '*.py' -or -name '*.js' \) -not -path '*venv*' -print0 | xargs -0 grep -cve '^[[:space:]]*
)

echo "Number of non-blank lines of code: $num_lines"

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.