feat(fix_filenames): Separate Words in filenames not separated by special char
This commit is contained in:
1 parent
d3410521bd
commit
0c8f33559d
1 file changed
+26
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Usage:
|
||||
# ./fix_test.sh Test # preview
|
||||
# ./fix_test.sh Test apply # rename
|
||||
|
||||
pattern="${1:?Usage: $0 PATTERN [apply]}"
|
||||
apply="${2:-}"
|
||||
|
||||
find . -type f -print0 |
|
||||
while IFS= read -r -d '' f; do
|
||||
base=$(basename "$f")
|
||||
dir=$(dirname "$f")
|
||||
|
||||
newbase=$(printf '%s\n' "$base" |
|
||||
sed -E "s/${pattern}([A-Z])/${pattern}_\1/g")
|
||||
|
||||
if [[ "$base" != "$newbase" ]]; then
|
||||
if [[ "$apply" == "apply" ]]; then
|
||||
mv -- "$f" "$dir/$newbase"
|
||||
printf 'RENAMED: %s -> %s\n' "$f" "$dir/$newbase"
|
||||
else
|
||||
printf 'WOULD RENAME: %s -> %s\n' "$f" "$dir/$newbase"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
Reference in new issue
Block a user