Skip to content
Myr

rename_test.sh

This file

Path

rename_test.sh

52 lines · 1.2 KiB · Shell

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than f0f8ed1 point at it.

[Dev Deps] update `semver`Jordan Harbandbefore adoptionf0f8ed1

lines 1–52why, one step back
1#! /usr/bin/env bash
23find_name(){4 find test -name "*[\\/:\*\?\"<>\|]*" -o -name "*."5}67check_name() {8 if [ "$(find_name | wc -l)" != "0" ]; then9 printf '%s\n\n' "The following filenames contain unwanted characters:"10 find_name11 printf '\n%s\n%s\n' "Please run ./rename_test.sh" "If the problem persist, please open an issue."12 exit 113 else14 echo "Ok"15 fi16}1718rename_test() {19 local filename20 local new_filename21 while read -r filename; do22 # Even though it looks < and > are replaced by the same < and >, the latters are not ASCII code23 # If you check with 'cat -v rename_test.sh' you would see 's/</M-KM-^B/g' and 's/>/M-KM-^C/g'24 # M-KM-^B -> U+02C225 # M-KM-^C -> U+02C326 new_filename=$(echo "$filename" | sed -r \27 -e "s/\"/'/g" \28 -e 's/</˂/g' \29 -e 's/>/˃/g' \30 -e 's/^(.*)\.$/\1/'31 )32 printf '%s\n%s\n\n' "$filename" "$new_filename"33 [ "$filename" != "$new_filename" ] && git mv "$filename" "$new_filename"34 done < <(find_name)3536 if [ "$(find_name | wc -l)" != "0" ]; then37 echo "Still some files to treat:"38 find_name39 else40 echo "Done"41 fi42}4344main() {45 if [ "$1" = "--check" ]; then46 check_name47 else48 rename_test49 fi50}5152main "$@"