]> git.donarmstrong.com Git - bin.git/blob - sanitize_filename
remove convert_to_xls and .sa_bin
[bin.git] / sanitize_filename
1 #! /bin/bash
2 # replace spaces with underscores, lowercase everything, ditch multiple underscores, and ditch _.foo.
3 # should probably try to avoid overwriting existing files, but c'est la vie!
4
5 TEMP="$(getopt --longoptions 'anime' -- '' "$@")"
6 eval set -- "$TEMP"
7 set -e
8
9 ANIME_CUT=0
10
11
12 while [ $1 != "--" ]; do
13     case $1 in 
14         --anime)
15             ANIME_CUT=1
16             ;;
17     esac;
18     shift
19 done;
20 shift;
21 set -x
22 if [ "$ANIME_CUT" == 0 ]; then
23     rename 's/\s+/\_/g; s{[^\w\d.\/]}{\_}g; s/_$//g; $_ = lc($_); s/\_+/\_/g; s/\_\././; s/^_+//g; s/_+$//g;' "$@"
24 else
25     rename 's{\[[^\]\/]+\]}{}g; s{\([^\)\/]+\)}{}g; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././; s/^_+//; s/_+$//g;' "$@"
26 fi;