From: Don Armstrong Date: Fri, 2 Apr 2010 13:54:30 +0000 (+0000) Subject: fixup sanitize filename to handle leading - properly X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=351d1bbaddd11b8249891c227b49c6249784f84e;p=bin.git fixup sanitize filename to handle leading - properly --- diff --git a/sanitize_filename b/sanitize_filename index 13623ba..11574bc 100755 --- a/sanitize_filename +++ b/sanitize_filename @@ -1,4 +1,4 @@ -#! /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! @@ -9,7 +9,7 @@ set -e ANIME_CUT=0 -while [ $1 != '--' ]; do +while [ $1 != "--" ]; do case $1 in --anime) ANIME_CUT=1 @@ -25,7 +25,7 @@ while [ $1 != '--' ]; do done; shift; if [ "$ANIME_CUT" == 0 ]; then - rename 's/\s+/\_/g; s/[^\w\d.]/\_/g; s/_$//g; $_ = lc($_); s/\_+/\_/g; s/\_\././; s/^_+//g;' "$@" + rename 's/\s+/\_/g; s/[^\w\d.]/\_/g; s/_$//g; $_ = lc($_); s/\_+/\_/g; s/\_\././; s/^_+//g;' -- "$@" else - rename 's/\[[^\]]+\]//g; s/\([^\)]+\)//g; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././; s/^_+//;' "$@" + rename 's/\[[^\]]+\]//g; s/\([^\)]+\)//g; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././; s/^_+//;' -- "$@" fi; \ No newline at end of file