(scripts) "fixed and improved" whitespaceremover

This commit is contained in:
scbj
2026-04-30 16:27:23 +02:00
parent 2f77aee122
commit 2cee107b6f
+20 -10
View File
@@ -22,26 +22,31 @@ function remove-whitespace {
unset files unset files
for arg in $@; do for arg in $@; do
unset arg_found
case ${arg} in case ${arg} in
"-u" | "--unix") -*u* | --unix)
arg_found="true"
ffunix="true" ffunix="true"
continue
;; ;;
"-h" | "--help" | "-help") -*h* | --help)
arg_found="true"
help="true" help="true"
continue
;; ;;
"-n" | "--no-action") -*n* | --no-action)
arg_found="true"
no_action="true" no_action="true"
continue
;; ;;
"-s" | "--silent") -*s* | --silent)
arg_found="true"
silent="true" silent="true"
continue
;; ;;
*) ;; *) ;;
esac esac
if [[ -n "${arg_found}" ]]; then
continue
fi
if [[ -d "${arg}" ]]; then if [[ -d "${arg}" ]]; then
path_args+=("${arg}") path_args+=("${arg}")
continue continue
@@ -64,8 +69,8 @@ function remove-whitespace {
for arg in ${path_args[@]}; do for arg in ${path_args[@]}; do
files+=($( files+=($(
find "${arg}" \ find "${arg}" \
"${exclude_paths[@]/#/-not -path }" \ ${exclude_paths[@]/#/-not -path } \
"${exclude_files[@]/#/-not -name }" \ ${exclude_files[@]/#/-not -name } \
-type f \ -type f \
-exec grep -EIq "${grep_regex}" {} \; \ -exec grep -EIq "${grep_regex}" {} \; \
-print -print
@@ -75,6 +80,11 @@ function remove-whitespace {
grep -EIq "${grep_regex}" ${arg} && files+=("${arg}") grep -EIq "${grep_regex}" ${arg} && files+=("${arg}")
done done
if [[ -z "${files[@]}" ]] && [[ -n "${path_args}" ]]; then
echo "no files with trailing whitespace or dos style line endings found"
return 0
fi
if [[ -n "${help}" ]] || [[ -z "${files[@]}" ]]; then if [[ -n "${help}" ]] || [[ -z "${files[@]}" ]]; then
cat <<EOF cat <<EOF
Usage: remove-whitespace [-h] [-n] path [path] Usage: remove-whitespace [-h] [-n] path [path]