Skip to content

Commit e58ec5d

Browse files
committed
feat: impl wc-find.sh script for lines of code analysis
1 parent 05fdb88 commit e58ec5d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

wc-find.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Usage:
3+
#
4+
# 1 - Set some regex filter for `find` with `REGEX="..."`. Examples:
5+
# ```
6+
# REGEX=".*\.\(go\|rs\|js*\|ts*\|md\)" # Go, Rust, JS, TS, Markdown
7+
# REGEX=".*\.\(go\|rs\|md\)" # Go, Rust, Markdown
8+
# ```
9+
#
10+
# 2 - Run the script with REGEX as an env var.
11+
# ```
12+
# REGEX=$REGEX bash wc-find.sh
13+
# ```
14+
15+
echo "REGEX: $REGEX"
16+
17+
find . -regex "$REGEX" -exec wc -l {} + | tail -1
18+
19+
# Directory analysis
20+
for dir in */; do
21+
if [ -d "$dir" ]; then
22+
lines=$(find "$dir" -regex "$REGEX" -exec wc -l {} + 2>/dev/null | tail -1 | awk '{print $1}' || echo "0")
23+
files=$(find "$dir" -regex "$REGEX" | wc -l)
24+
echo "$dir: $files files, $lines lines"
25+
fi
26+
done | sort -k4 -nr

0 commit comments

Comments
 (0)