Skip to content

Commit 70c6bca

Browse files
authored
Merge pull request godotengine#8411 from Calinou/update-unused-images-script
Update `list-unused-images.sh` script for recent changes
2 parents 2fe1d6a + 49f1f01 commit 70c6bca

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

_tools/list-unused-images.sh

100644100755
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
3+
set -uo pipefail
4+
IFS=$'\n\t'
25

36
check_git_history=false
47

@@ -9,19 +12,17 @@ rm -f tmp-unused-images-history
912
# Exceptions are ignored, and for .svg files we also look for potential .png
1013
# files with the same base name, as they might be sources.
1114

12-
exceptions="docs_logo.svg tween_cheatsheet.png"
13-
14-
files=$(find -name "_build" -prune -o \( -name "*.png" -o -name "*.jpg" -o -name "*.svg" -o -name "*.gif" \) -print | sort)
15+
files=$(find -name "_build" -prune -o \( -iname "*.png" -o -iname "*.webp" -o -iname "*.jpg" -o -iname "*.svg" -o -iname "*.gif" \) -print | sort)
1516

1617
for path in $files; do
17-
file=$(basename $path)
18-
if echo "$exceptions" | grep -q "$file"; then
18+
file=$(basename "$path")
19+
if [[ "$path" == *./img/* ]]; then
1920
continue
2021
fi
2122
ext=${file##*.}
2223
base=${file%.*}
2324
found=$(rg -l ":: .*[ /]$file")
24-
if [ -z "$found" -a "$ext" == "svg" ]; then
25+
if [ -z "$found" ] && [ "$ext" == "svg" ]; then
2526
# May be source file.
2627
found=$(rg -l ":: .*[ /]$base.png")
2728
fi
@@ -30,11 +31,13 @@ for path in $files; do
3031
fi
3132
done
3233

34+
echo "Wrote list of unused images to: tmp-unused-images"
3335

3436
if [ "$check_git_history" = true ]; then
3537
for file in $(cat tmp-unused-images); do
3638
echo "File: $file"
37-
git log --diff-filter=A --follow $file
39+
git log --diff-filter=A --follow "$file"
3840
echo
3941
done > tmp-unused-images-history
42+
echo "Wrote list of unused images in Git history to: tmp-unused-images-history"
4043
fi

0 commit comments

Comments
 (0)