Skip to content

Instantly share code, notes, and snippets.

@oguz-ismail
Last active April 28, 2023 05:52
Show Gist options
  • Save oguz-ismail/509a49300b3e852f9e0fef0c3d160fe3 to your computer and use it in GitHub Desktop.
Save oguz-ismail/509a49300b3e852f9e0fef0c3d160fe3 to your computer and use it in GitHub Desktop.
rename pascal case to kebab case recursively
#!/bin/sh -
find . \
-type f \
-name '[A-Z]*' \
! -name '*[!0-9A-Za-z]*.*' \
-exec sh -c '
for pn; do
p=${pn%/*}/
fn=${pn#"$p"}
n=${fn%.*}
e=${fn#"$n"}
while true; do
case $n in
(*[!A-Z-][A-Z]*)
w=${n#"${n%[!A-Z-][A-Z]*}"} w=${w#?} n=${n%"$w"}-$w ;;
(*)
break
esac
done
n=$(printf '\''%s\n'\'' "$n" | tr A-Z a-z)
echo mv "$pn" "$p$n$e"
done' sh {} +
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment