From 5a9e37161e38ff105ed86d33b93a2c2e75dbb21b Mon Sep 17 00:00:00 2001 From: quak Date: Wed, 18 Feb 2026 23:39:07 +0100 Subject: [PATCH] added script to remove trailing whitespace --- scripts/trailing-whitespace.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 scripts/trailing-whitespace.sh diff --git a/scripts/trailing-whitespace.sh b/scripts/trailing-whitespace.sh new file mode 100755 index 0000000..d535d19 --- /dev/null +++ b/scripts/trailing-whitespace.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +files=($(find . -not -path "*/.git/*" -type f -exec grep -Iq . {} \; -print)) +unset trailing_whitespace + +for file in ${files[@]}; do + sed -i 's/\r$//' ${file} + if [[ -n "$(sed -ne '/[[:space:]]$/p' ${file})" ]]; then + sed -i 's/[[:space:]]$//' ${file} + trailing_whitespace+="${file}\n" + fi +done +echo "" + +if [[ -n "${trailing_whitespace}" ]]; then + tput setaf 1 + tput smso + echo "[ DO NOT LEAVE TRAILING WHITE SPACE IN PLAIN TEXT FILES !!! ]" + tput sgr0 + echo "" + echo "The following files contained whitespace:" + echo -e "${trailing_whitespace}" +fi