list-unused-images.sh 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/bash
  2. check_git_history=false
  3. rm -f tmp-unused-images
  4. rm -f tmp-unused-images-history
  5. # List images which might be unused.
  6. # Exceptions are ignored, and for .svg files we also look for potential .png
  7. # files with the same base name, as they might be sources.
  8. exceptions="docs_logo.png tween_cheatsheet.png"
  9. files=$(find -name "_build" -prune -o \( -name "*.png" -o -name "*.jpg" -o -name "*.svg" -o -name "*.gif" \) -print | sort)
  10. for path in $files; do
  11. file=$(basename $path)
  12. if echo "$exceptions" | grep -q "$file"; then
  13. continue
  14. fi
  15. ext=${file##*.}
  16. base=${file%.*}
  17. found=$(rg -l ":: .*[ /]$file")
  18. if [ -z "$found" -a "$ext" == "svg" ]; then
  19. # May be source file.
  20. found=$(rg -l ":: .*[ /]$base.png")
  21. fi
  22. if [ -z "$found" ]; then
  23. echo "$path" >> tmp-unused-images
  24. fi
  25. done
  26. if [ "$check_git_history" = true ]; then
  27. for file in $(cat tmp-unused-images); do
  28. echo "File: $file"
  29. git log --diff-filter=A --follow $file
  30. echo
  31. done > tmp-unused-images-history
  32. fi