Advertisement
Kusari

Code Composition Counter

Nov 5th, 2013 (edited)
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Composition Counter
  2. # Made by Gary
  3. # Figures out the percentages of different file extensions and their sizes (similarly to what Github displays but for bash)
  4. # Not really optimized that well but works fine
  5.  
  6. #!/bin/bash
  7.  
  8. shopt -s globstar nullglob dotglob
  9.  
  10. # First iteration to get total size
  11. fullsize=0
  12. for ext in c cpp txt asm inc md sh m4 s; do
  13.     files=(**/*."$ext" )
  14.  
  15.     for f in "${files[@]}"; do
  16.         fullsize=$(($fullsize + `stat --printf="%s" "%f"`))
  17.     done
  18. done
  19.  
  20. # Second iteration to get percentages
  21. for ext in c cpp txt asm inc md sh m4 s; do
  22.     totalsize=0
  23.     files=(**/*."$ext" )
  24.  
  25.     for f in "${files[@]}"; do
  26.         totalsize=$(($totalsize + `stat --printf="%s" "%f"`))
  27.     done
  28.  
  29.     divided=`echo "scale=8 ; $totalsize / $fullsize * 100" | bc`
  30.  
  31.     printf '%s:\t%d (%d bytes, %f%%)\n' "$ext" "${#files[@]}" "$totalsize" "$divided"
  32. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement