(scripts) fix for spaces in paths/arguments of whitespace remover

This commit is contained in:
zegonix
2026-05-27 18:22:18 +02:00
parent c1e058c61e
commit 19a37667fa
+12 -13
View File
@@ -23,7 +23,7 @@ function remove-whitespace {
unset args unset args
unset arguments unset arguments
for arg in $@; do for arg in "$@"; do
if [[ "${arg}" =~ ^-[a-zA-Z]{2,}$ ]]; then if [[ "${arg}" =~ ^-[a-zA-Z]{2,}$ ]]; then
temp=($(echo ${arg} | grep --color=never -o ".")) temp=($(echo ${arg} | grep --color=never -o "."))
args+=(${temp[@]/#/-}) args+=(${temp[@]/#/-})
@@ -32,14 +32,14 @@ function remove-whitespace {
fi fi
done done
for arg in ${args[@]}; do for arg in "${args[@]}"; do
[[ "${arg}" != "--" ]] && arguments+=("${arg}") [[ "${arg}" != "--" ]] && arguments+=("${arg}")
done done
unset args unset args
for arg in ${arguments[@]}; do for arg in "${arguments[@]}"; do
unset arg_found unset arg_found
case ${arg} in case "${arg}" in
"-u" | "--unix") "-u" | "--unix")
arg_found="true" arg_found="true"
ffunix="true" ffunix="true"
@@ -82,18 +82,18 @@ function remove-whitespace {
grep_regex=$'[[:blank:]]+\r?$' grep_regex=$'[[:blank:]]+\r?$'
fi fi
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
)) )")
done done
for arg in ${file_args[@]}; do for arg in "${file_args[@]}"; do
grep -EIq "${grep_regex}" ${arg} && files+=("${arg}") grep -EIq "${grep_regex}" "${arg}" && files+=("${arg}")
done done
if [[ -z "${files[@]}" ]] && [[ -n "${path_args}" ]]; then if [[ -z "${files[@]}" ]] && [[ -n "${path_args}" ]]; then
@@ -124,7 +124,7 @@ EOF
fi fi
if [[ -z "${no_action}" ]]; then if [[ -z "${no_action}" ]]; then
for file in ${files[@]}; do for file in "${files[@]}"; do
if [[ -n "${ffunix}" ]]; then if [[ -n "${ffunix}" ]]; then
sed -i "${sed_cmd}" ${file} sed -i "${sed_cmd}" ${file}
else else
@@ -139,7 +139,7 @@ EOF
tput smso tput smso
echo "The following files contain whitespace:" echo "The following files contain whitespace:"
tput sgr0 tput sgr0
for file in ${files[@]}; do for file in "${files[@]}"; do
echo "${file}" echo "${file}"
done done
elif [[ -z "${silent}" ]] && elif [[ -z "${silent}" ]] &&
@@ -148,9 +148,8 @@ EOF
tput smso tput smso
echo "The following files contained whitespace:" echo "The following files contained whitespace:"
tput sgr0 tput sgr0
for file in ${files[@]}; do for file in "${files[@]}"; do
echo "${file}" echo "${file}"
done done
fi fi
} }