diff --git a/scripts/trailing-whitespace.sh b/scripts/trailing-whitespace.sh index da04b80..3d49355 100755 --- a/scripts/trailing-whitespace.sh +++ b/scripts/trailing-whitespace.sh @@ -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 <