X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sanitize_filename;h=e56e3451b12169a0352ad0bb01ba4fc98cef8cc0;hb=dcce90e77c92202b5fadca48de6fd1cefc41ff79;hp=3e6d70557ec24dacc5010ba00530549b5b409e8a;hpb=1d997e7d68fe0ab078581c5e9bcd722bc0a5985d;p=bin.git diff --git a/sanitize_filename b/sanitize_filename index 3e6d705..e56e345 100755 --- a/sanitize_filename +++ b/sanitize_filename @@ -1,29 +1,26 @@ -#! /bin/sh +#! /bin/bash # replace spaces with underscores, lowercase everything, ditch multiple underscores, and ditch _.foo. # should probably try to avoid overwriting existing files, but c'est la vie! -set - $(getopt -u --longoptions 'anime' -- '' "$@") + +TEMP="$(getopt --longoptions 'anime' -- '' "$@")" +eval set -- "$TEMP" set -e ANIME_CUT=0 -while [ $1 != '--' ]; do +while [ $1 != "--" ]; do case $1 in --anime) ANIME_CUT=1 ;; - --restart) - RESTART=1 - ;; - --force) - FORCE=1 - ;; esac; shift done; shift; +set -x if [ "$ANIME_CUT" == 0 ]; then - rename 's/\s+/\_/g; $_ = lc($_); s/\_+/\_/g; s/\_\././' "$@" + rename 's/\s+/\_/g; s{[^\w\d.\/]}{\_}g; s/_$//g; $_ = lc($_); s/\_+/\_/g; s/\_\././; s/^_+//g; s/_+$//g;' "$@" else - rename 's/\[[^\]]+\]//g; s/^_+//; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././' "$@" -fi; \ No newline at end of file + rename 's{\[[^\]\/]+\]}{}g; s{\([^\)\/]+\)}{}g; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././; s/^_+//; s/_+$//g;' "$@" +fi;