Fixes issues with globbing files with partial match(#23)

Co-authored-by: Joakim Sørensen <hi@ludeeus.dev>
This commit is contained in:
pvogt09 2020-07-28 13:54:55 +02:00 committed by GitHub
parent c7d4e499f1
commit 73cbb64041
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 18 deletions

View File

@ -10,6 +10,7 @@ declare -a excludes
declare -a tmp declare -a tmp
statuscode=0 statuscode=0
shebangregex="^#! */[^ ]*/(env *)?[abkz]*sh"
excludes+=( ! -path *./.git/* ) excludes+=( ! -path *./.git/* )
excludes+=( ! -path *.go ) excludes+=( ! -path *.go )
@ -25,34 +26,38 @@ readarray -d '' filepaths < <(find . -type f "${excludes[@]}" \
'(' \ '(' \
\ \
-name '*.bash' \ -name '*.bash' \
-o -path '*/.bash*' \ -o -name '.bashrc' \
-o -path '*/bash*' \ -o -name 'bashrc' \
-o -name '.bash_aliases' \
-o -name '.bash_completion' \
-o -name '.bash_login' \
-o -name '.bash_logout' \
-o -name '.bash_profile' \
-o -name 'bash_profile' \
-o -name '*.ksh' \ -o -name '*.ksh' \
-o -name 'ksh*' \
-o -path '*/.ksh*' \
-o -path '*/ksh*' \
-o -name 'suid_profile' \ -o -name 'suid_profile' \
-o -name '*.zsh' \ -o -name '*.zsh' \
-o -name '.zlogin*' \ -o -name '.zlogin' \
-o -name 'zlogin*' \ -o -name 'zlogin' \
-o -name '.zlogout*' \ -o -name '.zlogout' \
-o -name 'zlogout*' \ -o -name 'zlogout' \
-o -name '.zprofile*' \ -o -name '.zprofile' \
-o -name 'zprofile*' \ -o -name 'zprofile' \
-o -path '*/.zsh*' \ -o -name '.zsenv' \
-o -path '*/zsh*' \ -o -name 'zsenv' \
-o -name '.zshrc' \
-o -name 'zshrc' \
-o -name '*.sh' \ -o -name '*.sh' \
-o -path '*/.profile*' \ -o -path '*/.profile' \
-o -path '*/.shlib*' \ -o -path '*/profile' \
-o -path '*/shlib*' \ -o -name '*.shlib' \
')'\ ')'\
\ \
-print0) -print0)
readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0) readarray -d '' tmp < <(find . "${excludes[@]}" -type f ! -name '*.*' -perm /111 -print0)
for file in "${tmp[@]}"; do for file in "${tmp[@]}"; do
head -n1 "$file" | grep -Eqs "^#! */[^ ]*/(env *)?[abkz]*sh" || continue head -n1 "$file" | grep -Eqs "$shebangregex" || continue
filepaths+=("$file") filepaths+=("$file")
done done

6
testfiles/bashfile.c Normal file
View File

@ -0,0 +1,6 @@
/* C code test file
* file that should not be matched for shellcheck runs
*/
int main(void) {
return 0;
}