# Composition Counter
# Made by Gary
# Figures out the percentages of different file extensions and their sizes (similarly to what Github displays but for bash)
# Not really optimized that well but works fine
#!/bin/bash
shopt -s globstar nullglob dotglob
# First iteration to get total size
fullsize=0
for ext in c cpp txt asm inc md sh m4 s; do
files=(**/*."$ext" )
for f in "${files[@]}"; do
fullsize=$(($fullsize + `stat --printf="%s" "%f"`))
done
done
# Second iteration to get percentages
for ext in c cpp txt asm inc md sh m4 s; do
totalsize=0
files=(**/*."$ext" )
for f in "${files[@]}"; do
totalsize=$(($totalsize + `stat --printf="%s" "%f"`))
done
divided=`echo "scale=8 ; $totalsize / $fullsize * 100" | bc`
printf '%s:\t%d (%d bytes, %f%%)\n' "$ext" "${#files[@]}" "$totalsize" "$divided"
done
Comments