summaryrefslogtreecommitdiff
path: root/sanitize
blob: c99a31e98322c7e6ee1c25af3052ef70a35d3e45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/env bash

# This script sanitizes a given file or directory. Can take multiple files/dirs
# as argument.
# It replaces all whitespace and special characters with a dash, removes ?, !
# and various types of brackets entirely and translates all characters to
# lower case. Camel case is also translated to dashes.
# Basically, the goal is to have filenames with ONLY lower case and dashes.

# Behold the most disgusting regex ever

perl-rename 's|([a-z])([A-Z])|$1-$2|g;s/\,//g;s/\x27//g;s/\.(?![^.]+$)//g;s/\&/and/g;s/@/-/g;s/ /-/g;s/_/-/g;s/--+/-/g;s/\[//g;s/\]//g;s/\(//g;s/\)//g;s/\{//g;s/\}//g;s/【//g;s/】//g;s/://g;s/\!+//g;s/?//g;s/|//g;s/\"//g;s/“//g;s/”//g;y/A-Z/a-z/' "$@";