Skip to content

Non ASCII characters are ignored #7

@takyros

Description

@takyros

In my case, i had to rename a bunch of files with uppercase, spaces, and some spanish character (ñ, ó, etc..) but such characters were ignored in the process.
e.g.:

LEÓN NUEVO TEXTO PEQUEÑO.png -> leÓn-nuevo-texto-pequeÑo.png

I slightly modified the "ignore_case" section to cover those cases, but yes i understand this solution is only valid for a subset of non ASCII chars, plus it only has effect if ignore_case is not enabled.

## Optionally convert to lowercase
  if [ "$ignore_case" -eq 0 ]; then
  # Slugify only the filename
  # Separate path and filename
  directory=$(dirname "$target")
  filename=$(basename "$target")
      # Convert to lowercase and replace accented characters in filename only
      filename=$(echo "$filename" | awk '{print tolower($0)}' \
                  | sed -e 's/[áàäâ]/a/g' \
                        -e 's/[éèëê]/e/g' \
                        -e 's/[íìïî]/i/g' \
                        -e 's/[óòöô]/o/g' \
                        -e 's/[úùüû]/u/g' \
                        -e 's/[ñ]/n/g' \
                        -e 's/[^a-z0-9._]/-/g')  # Keep ., and _ intact in filename
  # Reconstruct full path with slugified filename
  target="$directory/$filename"
  fi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions