Last active
February 28, 2023 09:25
-
-
Save alirezaarzehgar/0efec924b11cd6c2dc9c14564f902fd5 to your computer and use it in GitHub Desktop.
Sort source files with its lines.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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