Skip to content

Instantly share code, notes, and snippets.

@alirezaarzehgar
Last active February 28, 2023 09:25
Show Gist options
  • Select an option

  • Save alirezaarzehgar/0efec924b11cd6c2dc9c14564f902fd5 to your computer and use it in GitHub Desktop.

Select an option

Save alirezaarzehgar/0efec924b11cd6c2dc9c14564f902fd5 to your computer and use it in GitHub Desktop.
Sort source files with its lines.
#!/usr/bin/env bash
if [ "$1" ]; then
cd "$1" || exit
fi
exts="*.[ch]"
dirs=$(ls -d -- */ 2>/dev/null)
if [ "${dirs}" ]; then
for d in ${dirs}; do
count=0
for f in $(find "$d" -type f -name "${exts}"); do
lines=$(wc -l "$f" | cut -f1 -d" ")
count=$((count + lines))
done
echo "$count: $d"
done
else
for f in $(find . -type f -name "${exts}"); do
lines=$(wc -l "$f" | cut -f1 -d" ")
echo "$lines: $f"
done
fi | sort -n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment