commit 8388bd9c056fa19ebb0e57c31c1c0fac8e8fab7d Author: Voomra Date: Sat Nov 2 23:51:02 2019 +0300 commit diff --git a/script.sh b/script.sh new file mode 100644 index 0000000..f7ffa6f --- /dev/null +++ b/script.sh @@ -0,0 +1,35 @@ +#!bash + +PERL_SCRIPT=$(cat <<'EOF' +@files = split(/:/, $ARGV[0]); +@new_files = (); +foreach $file (@files) { + if ($file =~ m#^\./.+\.(jpe?g|png|gif)$#) { + ($mtime) = (stat($file))[9]; + $ext = $1; + $new_file = "./$mtime.$ext"; + if ($new_file eq $file) { + next; + } + while (grep $_ eq $new_file, @new_files) { + if (! defined $suffix) { + $suffix = "-1"; + } else { + $suffix = $suffix - 1; + } + $new_file = "./$mtime$suffix.$ext"; + } + push(@new_files, $new_file); + $file =~ s#([ \(\)])#\\$1#g; + print "mv -n \"$file\" $new_file\n"; + undef $suffix; + } +} +$count = @new_files; +print "echo \"Renamed: $count\"\n"; +EOF +) + +renamer() { + find . -maxdepth 1 -type f -print | tr '\n' ':' | xargs -I{} -- perl -e "$PERL_SCRIPT" '{}' | xargs -n1 -I{} -- bash -c '{}' +}