]> git.donarmstrong.com Git - bin.git/blobdiff - sanitize_filename
add mutt alias which executes neomutt if that exists
[bin.git] / sanitize_filename
index 41f8b39cebb0281e415d8809559361cffec5dbec..e56e3451b12169a0352ad0bb01ba4fc98cef8cc0 100755 (executable)
@@ -1,4 +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!
-rename 's/\s+/\_/g; $_ = lc($_); s/\_+/\_/g; s/\_\././' "$@"
+
+TEMP="$(getopt --longoptions 'anime' -- '' "$@")"
+eval set -- "$TEMP"
+set -e
+
+ANIME_CUT=0
+
+
+while [ $1 != "--" ]; do
+    case $1 in 
+       --anime)
+           ANIME_CUT=1
+           ;;
+    esac;
+    shift
+done;
+shift;
+set -x
+if [ "$ANIME_CUT" == 0 ]; then
+    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+/\_/g; $_ = lc($_); s/[_-]+/\_/g; s/\_\././; s/^_+//; s/_+$//g;' "$@"
+fi;