Merge 01661e9bba239d73390c142097b5344f09640bab into ea3e1e14cc49d68c9900fb05d9ee7bb9e719688e

This commit is contained in:
Emre AKYÜZ 2023-10-31 03:32:49 -06:00 committed by GitHub
commit a6d8b0f4aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

18
.local/bin/fixnames Normal file
View File

@ -0,0 +1,18 @@
#!/bin/dash
[ "$(id -u)" = "0" ] && echo "This script should not be run as root" >&2 && exit 1
find . -depth \( -path '*/.*' -o -path '*/.*/*' \) -prune -o \( -type f -o -type d \) -print0 | xargs -0 -P 0 -I {} dash -c '
base="${1##*/}"
path="${1%/*}"
pattern="s/[^a-zA-Z0-9 ._-]//g; s/[ .-]/_/g; s/_+/_/g; s/^_+//; s/_+$//; s/[A-Z]/\L&/g"
[ -f "$1" ] && pattern="$pattern; s/_([^_]+)$/.\\1/"
new_name="$(echo "$base" | sed -E "$pattern")"
[ "$base" != "$new_name" ] && [ -e "$path/$new_name" ] && new_name="${$}_${new_name}"
[ "$base" != "$new_name" ] && mv "$1" "$path/$new_name"
' _ {}