]> git.donarmstrong.com Git - bin.git/blob - sanitize_filename
* add support for dealing with anime filenames to sanitize_filename
[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 set - $(getopt -u --longoptions 'anime' -- '' "$@")
5 set -e
6
7 ANIME_CUT=0
8
9
10 while [ $1 != '--' ]; do
11     case $1 in 
12         --anime)
13             ANIME_CUT=1
14             ;;
15         --restart)
16             RESTART=1
17             ;;
18         --force)
19             FORCE=1
20             ;;
21     esac;
22     shift
23 done;
24 shift;
25 if [ "$ANIME_CUT" == 0 ]; then
26     rename 's/\s+/\_/g; $_ = lc($_); s/\_+/\_/g; s/\_\././' "$@"
27 else
28     rename 's/\[[^\]]+\]//g; s/^_+//; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././' "$@"
29 fi;