-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
sanitize
executable file
·43 lines (42 loc) · 1.07 KB
/
sanitize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/zsh
# vim:ft=zsh
# abstract: sanitize filenames
if [[ $1 == '-l' || $1 == '-tolower' ]]; then
# lowercase everything
shift
prename 's/(.+)/\L$1/' $@
exit
elif [[ $1 == '-u' || $1 == '-toupper' ]]; then
# uppercase everything
shift
prename 's/(.+)/\U$1/' $@
exit
elif [[ $1 == '-t' || $1 == '-totitle' ]]; then
# titlecase words globally
shift
prename 's/(\w+)/\u$1/g' $@
exit
elif [[ $1 == '-lf' || $1 == '-lcfirst' ]]; then
# lcfirst words globally
shift
prename 's/(\w+)/lcfirst($1)/eg' $@
exit
elif [[ $1 == '-uf' || $1 == '-ucfirst' ]]; then
# ucfirst words globally
shift
prename 's/(\w+)/ucfirst($1)/eg' $@
exit
elif [[ $1 == '-x' || $1 == '-fixall' ]]; then
shift
prename "s/[',&!?#]//g"';s/[åä]/a/g; s/ö/o/g; s/\s/_/g; s/_-_/-/g; s/\[|]//g; s/[()]//g; s/[.]_/_/g; s/([._-]){2,}/$1/g;' -- $@
exit
else
printf "usage: $0 [ OPTIONS ]\n\n OPTIONS:\n\n%s\n%s\n%s\n%s\n%s\n%s\n" \
' -l, -tolower' \
' -u, -toupper' \
' -t, -totitle' \
' -lf, -lcfirst' \
' -uf, -ucfirst' \
' -x, -fixall'
exit
fi