From 138950d31dc04bc310afd994321ebee750a38bdb Mon Sep 17 00:00:00 2001 From: clyhtsuriva Date: Thu, 15 Jun 2023 21:59:24 +0200 Subject: Rename convert_filenames.sh into convert-filenames.sh --- bin/convert-filenames.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ bin/convert_filenames.sh | 64 ------------------------------------------------ 2 files changed, 64 insertions(+), 64 deletions(-) create mode 100755 bin/convert-filenames.sh delete mode 100755 bin/convert_filenames.sh diff --git a/bin/convert-filenames.sh b/bin/convert-filenames.sh new file mode 100755 index 0000000..9ccba13 --- /dev/null +++ b/bin/convert-filenames.sh @@ -0,0 +1,64 @@ +#!/usr/bin/env bash +# Clyhtsuriva + +# Check if file arguments are provided +if [ "$#" -lt 1 ]; then + echo "Usage: $0 [ ...]" + exit 1 +fi + +# Loop through all file arguments +for file in "$@"; do + # Check if the file exists + if [ ! -f "$file" ]; then + echo "File '$file' does not exist." + exit 1 + fi + + echo "$file" + + # Get the lowercase version of the file name + new_name=$(basename "$file" | tr '[:upper:]' '[:lower:]') + echo "$new_name" + +# Replace parentheses, brackets, and square brackets with dashes + new_name=${new_name//[()]/-} + new_name=${new_name//\[/-} + new_name=${new_name//\]/-} + echo "$new_name" + + # Remove special characters that are not '_', '-', '.' and spaces. + new_name=${new_name//[^a-zA-Z0-9_. -]/} + echo "$new_name" + + # Replace spaces with '_' + new_name=${new_name// / } + new_name=${new_name// /_} + echo "$new_name" + + # Replace consecutive occurrences of '_-_', '_-', '-_' and '-_-' by '-'. + new_name=${new_name//_\-_/-} + new_name=${new_name//_\-/-} + new_name=${new_name//-\_/-} + new_name=${new_name//-\-_/-} + echo "$new_name" + + # Replace consecutive occurrences of '-.' by '.'. + new_name=${new_name//\-\./.} + echo "$new_name" + + # Replace consecutive occurrences of '--' with a single '-'. + new_name=${new_name//--/-} + echo "$new_name" + + # Replace multiple underscores with single '_'. + new_name=${new_name//__/_} + echo "$new_name" + + # Remove leading special characters + new_name=${new_name##[![:alnum:]]} + echo "$new_name" + + # Rename the file + mv "$file" "$(dirname "$file")/$new_name" +done diff --git a/bin/convert_filenames.sh b/bin/convert_filenames.sh deleted file mode 100755 index 9ccba13..0000000 --- a/bin/convert_filenames.sh +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env bash -# Clyhtsuriva - -# Check if file arguments are provided -if [ "$#" -lt 1 ]; then - echo "Usage: $0 [ ...]" - exit 1 -fi - -# Loop through all file arguments -for file in "$@"; do - # Check if the file exists - if [ ! -f "$file" ]; then - echo "File '$file' does not exist." - exit 1 - fi - - echo "$file" - - # Get the lowercase version of the file name - new_name=$(basename "$file" | tr '[:upper:]' '[:lower:]') - echo "$new_name" - -# Replace parentheses, brackets, and square brackets with dashes - new_name=${new_name//[()]/-} - new_name=${new_name//\[/-} - new_name=${new_name//\]/-} - echo "$new_name" - - # Remove special characters that are not '_', '-', '.' and spaces. - new_name=${new_name//[^a-zA-Z0-9_. -]/} - echo "$new_name" - - # Replace spaces with '_' - new_name=${new_name// / } - new_name=${new_name// /_} - echo "$new_name" - - # Replace consecutive occurrences of '_-_', '_-', '-_' and '-_-' by '-'. - new_name=${new_name//_\-_/-} - new_name=${new_name//_\-/-} - new_name=${new_name//-\_/-} - new_name=${new_name//-\-_/-} - echo "$new_name" - - # Replace consecutive occurrences of '-.' by '.'. - new_name=${new_name//\-\./.} - echo "$new_name" - - # Replace consecutive occurrences of '--' with a single '-'. - new_name=${new_name//--/-} - echo "$new_name" - - # Replace multiple underscores with single '_'. - new_name=${new_name//__/_} - echo "$new_name" - - # Remove leading special characters - new_name=${new_name##[![:alnum:]]} - echo "$new_name" - - # Rename the file - mv "$file" "$(dirname "$file")/$new_name" -done -- cgit v1.2.3