From e5bcdff29feb328481cc8035f2a5acf6e89eae8e Mon Sep 17 00:00:00 2001 From: zegonix Date: Sun, 3 May 2026 10:10:37 +0200 Subject: [PATCH] (scripts) whitespace remover .. --- scripts/trailing-whitespace.sh | 40 +++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/scripts/trailing-whitespace.sh b/scripts/trailing-whitespace.sh index 3d49355..6daf7d7 100755 --- a/scripts/trailing-whitespace.sh +++ b/scripts/trailing-whitespace.sh @@ -4,7 +4,7 @@ function remove-whitespace { # exclude file types # (ignore generated files/directories) exclude_paths=( - "*/.git/*" + '*/.git/*' ) exclude_files=( "*.lst" @@ -20,23 +20,39 @@ function remove-whitespace { unset file_args unset ffunix unset files + unset args + unset arguments for arg in $@; do + if [[ "${arg}" =~ ^-[a-zA-Z]{2,}$ ]]; then + temp=($(echo ${arg} | grep --color=never -o ".")) + args+=(${temp[@]/#/-}) + else + args+=("${arg}") + fi + done + + for arg in ${args[@]}; do + [[ "${arg}" != "--" ]] && arguments+=("${arg}") + done + unset args + + for arg in ${arguments[@]}; do unset arg_found case ${arg} in - -*u* | --unix) + "-u" | "--unix") arg_found="true" ffunix="true" ;; - -*h* | --help) + "-h" | "--help") arg_found="true" help="true" ;; - -*n* | --no-action) + "-n" | "--no-action") arg_found="true" no_action="true" ;; - -*s* | --silent) + "-s" | "--silent") arg_found="true" silent="true" ;; @@ -117,9 +133,16 @@ EOF done fi - echo "" - - if [[ -z "${silent} ${no_action}" ]] && + if [[ -n "${no_action}" ]] && + [[ -n "${files}" ]]; then + tput setaf 1 + tput smso + echo "The following files contain whitespace:" + tput sgr0 + for file in ${files[@]}; do + echo "${file}" + done + elif [[ -z "${silent}" ]] && [[ -n "${files}" ]]; then tput setaf 1 tput smso @@ -129,4 +152,5 @@ EOF echo "${file}" done fi + }