]> git.donarmstrong.com Git - bin.git/blobdiff - sanitize_filename
fixup sanitize filename to handle leading - properly
[bin.git] / sanitize_filename
index 13623ba1aba0154eecadf8d21716dbcd1540338d..11574bc91ac8bc65f051696ee94d6c86cae589c9 100755 (executable)
@@ -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