]> git.donarmstrong.com Git - bin.git/blob - sanitize_filename
add ical2rem ical->reminder converter
[bin.git] / sanitize_filename
1 #! /bin/sh
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         --restart)
18             RESTART=1
19             ;;
20         --force)
21             FORCE=1
22             ;;
23     esac;
24     shift
25 done;
26 shift;
27 if [ "$ANIME_CUT" == 0 ]; then
28     rename 's/\s+/\_/g; s/[^\w\d.]/\_/g; s/^_+//g; s/_$//g; $_ = lc($_); s/\_+/\_/g; s/\_\././' "$@"
29 else
30     rename 's/\[[^\]]+\]//g; s/^_+//; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././' "$@"
31 fi;