summaryrefslogtreecommitdiff
path: root/.local/bin/mvtr
blob: 3fc9b4cdd763acb043046b2e93b95e749b84d2e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh

# can use ls pipe to sed pipe to bash, similar to eval? see comment at link:
# link also show perl-rename approach
# 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

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 '{}' \;

# 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/