Skip to content

Instantly share code, notes, and snippets.

@cornfeedhobo
Last active March 7, 2025 00:23
Show Gist options
  • Save cornfeedhobo/18f88462d39ed7f2b7e9465c021f97d4 to your computer and use it in GitHub Desktop.
Save cornfeedhobo/18f88462d39ed7f2b7e9465c021f97d4 to your computer and use it in GitHub Desktop.
dedup games, images, and videos for emulationstation
#!/usr/bin/env bash
set -eu -o pipefail
# Find duplicates based on the root name, and loop through them
find . -type f -name '*.zip' -printf '%f\n' | cut -d'(' -f1 | sort | uniq -d | while read -r line; do
# Prompt the user for which file they want to keep from all the duplicates
# Note: must account for titles that share the same root name
# e.g. 'Foobar' and 'Foobar 2'
choice="$(fzf < <(find . -type f -name "${line} (*.zip" -printf '%f\n'))"
# This is meant for emulationstation. Search for images and videos too.
_find() {
find . -type f \
-not -name "${choice}" \
-not -name "${choice%.zip}-image.*" \
-not -name "${choice%.zip}-thumb.*" \
-not -name "${choice%.zip}-marquee.*" \
-not -name "${choice%.zip}-video.*" \
-name "${line} (*"
}
# List all files that will be deleted.
_find
# Confirm before deleting
while read -n1 -r -p "Proceed with delete (y/n/q)? " confirm </dev/tty; do
echo ''
case "$confirm" in
y | Y) { _find | xargs -d '\n' rm ; } && clear && break ;;
n | N) break ;;
q | Q) exit ;;
*) continue ;;
esac
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment