X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=sanitize_filename;h=a6dc4c10038315e89ad59dc81d78926dfd32bdc8;hb=54623805896b237f3b6ea9e3dce95b4ea593cef2;hp=19737a23cd8ccb3ba288eb3b9db171a1830bbea9;hpb=2a7f771312c356a87e2f7f5ae93fdc5cc082d44c;p=bin.git diff --git a/sanitize_filename b/sanitize_filename index 19737a2..a6dc4c1 100755 --- a/sanitize_filename +++ b/sanitize_filename @@ -1,15 +1,15 @@ -#! /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! TEMP="$(getopt --longoptions 'anime' -- '' "$@")" -eval set -- $TEMP +eval set -- "$TEMP" 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; 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/\([^\)]+\)//g; s/^_+//; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././' "$@" + rename 's{\[[^\]\/]+\]}{}g; s{\([^\)\/]+\)}{}g; s/\s+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././; s/^_+//; s/_+$//g;' -- "$@" fi; \ No newline at end of file