summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxyz <gky44px1999@gmail.com>2021-10-07 14:58:20 -0700
committerxyz <gky44px1999@gmail.com>2021-10-07 14:58:20 -0700
commit37fa7ff841c0c8294b11fc79e8036f345199719c (patch)
tree6b0d51c145c9acbcb9c71fb743680106fa3e31dd
parent30881d30a41db1f41eec47d7c39730c42c525ac9 (diff)
mvtr
-rwxr-xr-x.local/bin/mvtr11
1 files changed, 4 insertions, 7 deletions
diff --git a/.local/bin/mvtr b/.local/bin/mvtr
index 3fc9b4cd..850f8dba 100755
--- a/.local/bin/mvtr
+++ b/.local/bin/mvtr
@@ -5,13 +5,10 @@
# https://linuxconfig.org/rename-all-files-from-uppercase-to-lowercase-characters
# if only change ' ' to '_' `rename` might be sufficient, for upper to lower case might need perl-rename if want concise
-# pass awk script as argument trick from url:
-# https://unix.stackexchange.com/questions/282503/right-syntax-for-awk-usage-in-combination-with-other-command-inside-xargs-sh-c
-# -exec can't replace -execdir here, see cli notes for the -exec way
+# ./_filename will be renamed ./filename, not what I want, need improve
+# -exec can't replace -execdir here, can write a -exec version
-find "$@" -depth -execdir sh -c 'mv -nvT -- "$1" "$(echo "$1" | tr "[:upper:] " "[:lower:]_" | tr -s "[:punct:]" | sed -E -e "s#/-#/#g" -e "s/_([-().,])/\1/g" -e "s/([-(),])_/\1/g" | tr -s "[:punct:]")"' shell '{}' \;
-
-#find "$@" -depth -execdir sh -c 'mv -nvT -- "$1" "$(echo "$1" | tr "[:upper:] " "[:lower:]_" | tr -s "[:punct:]" | sed -E -e "s#/-#/#g" -e "s/_([[:punct:]])/\1/g" -e "s/([[:punct:]])_/\1/g" | tr -s "[:punct:]")"' shell '{}' \;
+find "$@" -depth -execdir sh -c 'dest="$(echo "$1" | tr -d "\047" | sed -E -e "s/([[:lower:]])([[:upper:]])/\1_\2/g" | tr "[:upper:] " "[:lower:]_" | tr -s "[:punct:]" | sed -E -e "s#/-#/#g" -e "s/_([[:punct:]])/\1/g" -e "s/([[:punct:]])_/\1/g" | tr -s "[:punct:]")"; [ -e "$dest" ] || mv -v -- "$1" "$dest"' shell '{}' \;
# for test
-#mkdir -p ~/test/TE\ ST/; rm -rf ~/test/TE\ ST/1t/; cp -r ~/test/0t/ ~/test/TE\ ST/1t/; mvtr ~/test/TE\ ST/1t/; tree ~/test/TE\ ST/1t/
+#mkdir -p ~/test/A\ A/; rm -rf ~/test/A\ A/1t/; cp -r ~/test/0t/ ~/test/A\ A/1t/; time mvtr ~/test/A\ A/1t/; tree ~/test/A\ A/1t/