From: Siraaj Khandkar Date: Mon, 4 May 2020 20:43:45 +0000 (-0400) Subject: Add dotnet new project cleanup script X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=c35dfd6a9561088bb092b4ae83d694403219968d;p=khome.git Add dotnet new project cleanup script --- diff --git a/home/bin/dotnet-new-cleanup b/home/bin/dotnet-new-cleanup new file mode 100755 index 0000000..d5b5044 --- /dev/null +++ b/home/bin/dotnet-new-cleanup @@ -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'