(scripts) "fixed and improved" whitespaceremover
This commit is contained in:
@@ -22,26 +22,31 @@ function remove-whitespace {
|
||||
unset files
|
||||
|
||||
for arg in $@; do
|
||||
unset arg_found
|
||||
case ${arg} in
|
||||
"-u" | "--unix")
|
||||
-*u* | --unix)
|
||||
arg_found="true"
|
||||
ffunix="true"
|
||||
continue
|
||||
;;
|
||||
"-h" | "--help" | "-help")
|
||||
-*h* | --help)
|
||||
arg_found="true"
|
||||
help="true"
|
||||
continue
|
||||
;;
|
||||
"-n" | "--no-action")
|
||||
-*n* | --no-action)
|
||||
arg_found="true"
|
||||
no_action="true"
|
||||
continue
|
||||
;;
|
||||
"-s" | "--silent")
|
||||
-*s* | --silent)
|
||||
arg_found="true"
|
||||
silent="true"
|
||||
continue
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
if [[ -n "${arg_found}" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [[ -d "${arg}" ]]; then
|
||||
path_args+=("${arg}")
|
||||
continue
|
||||
@@ -64,8 +69,8 @@ function remove-whitespace {
|
||||
for arg in ${path_args[@]}; do
|
||||
files+=($(
|
||||
find "${arg}" \
|
||||
"${exclude_paths[@]/#/-not -path }" \
|
||||
"${exclude_files[@]/#/-not -name }" \
|
||||
${exclude_paths[@]/#/-not -path } \
|
||||
${exclude_files[@]/#/-not -name } \
|
||||
-type f \
|
||||
-exec grep -EIq "${grep_regex}" {} \; \
|
||||
-print
|
||||
@@ -75,6 +80,11 @@ function remove-whitespace {
|
||||
grep -EIq "${grep_regex}" ${arg} && files+=("${arg}")
|
||||
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
|
||||
cat <<EOF
|
||||
Usage: remove-whitespace [-h] [-n] path [path]
|
||||
|
||||
Reference in New Issue
Block a user