From c35dfd6a9561088bb092b4ae83d694403219968d Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Mon, 4 May 2020 16:43:45 -0400 Subject: [PATCH] Add dotnet new project cleanup script --- home/bin/dotnet-new-cleanup | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 home/bin/dotnet-new-cleanup 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' -- 2.20.1