Add dotnet new project cleanup script
authorSiraaj Khandkar <siraaj@khandkar.net>
Mon, 4 May 2020 20:43:45 +0000 (16:43 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Mon, 4 May 2020 20:43:45 +0000 (16:43 -0400)
home/bin/dotnet-new-cleanup [new file with mode: 0755]

diff --git a/home/bin/dotnet-new-cleanup b/home/bin/dotnet-new-cleanup
new file mode 100755 (executable)
index 0000000..d5b5044
--- /dev/null
@@ -0,0 +1,50 @@
+#! /bin/sh
+
+BOM='^\xef\xbb\xbf'
+
+case "`uname`" in
+    Darwin)
+        _sed=gsed;
+        _grep=ggrep;;
+    *)
+        _sed=sed;
+        _grep=grep;;
+esac
+
+case "$1" in
+    '') _dir=.;;
+     *) _dir="$1";;
+esac
+
+_find() {
+    _pattern="$1"
+    LC_ALL=C "$_grep" \
+        --color=never \
+        -rIcP \
+        --exclude-dir=.git \
+        "$_pattern" "$_dir" \
+    | awk -F: '$2 {print $1}'
+}
+
+_delete() {
+    _pattern="$1"
+    while read _file
+    do
+        tmp="`mktemp`"
+        LC_ALL=C "$_sed" "s/$_pattern//" "$_file" > "$tmp"
+        mv "$tmp" "$_file"
+    done
+}
+
+
+echo 'BOM:'
+echo '----'
+_find "$BOM"
+_find "$BOM" | _delete "$BOM"
+
+echo ''
+
+echo 'Trailing carriage return:'
+echo '-------------------------'
+_find '\r'
+_find '\r' | _delete '\r'
This page took 0.023213 seconds and 4 git commands to generate.