33
44gitgrep ()
55{
6- local out=$( git grep -I -P -n " $1 " |
7- grep -E ' ^(bash_completion|completions(-fallback|-core)?/|test/)' |
8- grep -Ev " ^test/runLint\>${filter_out: +|$filter_out } " )
6+ local pathspecs=(' bash_completion' ' completions-fallback/'
7+ ' completions-core/' ' test/' ' bash_completion.d/' ' :!:test/runLint'
8+ ' :!:test/docker/' ' :!:test/test-cmd-list.txt' )
9+ local filter_list
10+ read -ra filter_list <<< " $filter_out"
11+ pathspecs+=(" ${filter_list[@]/#/ " :!:" } " )
12+ local out=$(
13+ git grep -I -P -n " $1 " -- " ${pathspecs[@]} " |
14+ grep -Pv ' :[[:space:]]*(#|""")' # Ignore bash and python comments
15+ )
916 if [[ $out ]]; then
1017 printf ' ***** %s\n' " $2 "
1118 printf ' %s\n\n' " $out "
@@ -18,7 +25,7 @@ if ! cd "$(dirname "$0")/.."; then
1825 exit 1
1926fi
2027
21- cmdstart=' (^|[[:space:];&|]|\( )'
28+ cmdstart=' (?:(?: ^|[;&|()])[[:blank:]]*|\b(?:if|then|elif|else|for|while|until|do|coproc|command|builtin)[[:blank:]]+|{[[:blank:]]+ )'
2229filter_out=
2330
2431# Note: Since we started to use _comp_{awk,tail}, we do not have to care about
@@ -53,10 +60,10 @@ gitgrep "$cmdstart"'[ef]grep\b' \
5360# TODO: $ in sed subexpression used as an anchor (POSIX BRE optional, not in
5461# Solaris/FreeBSD)
5562
56- gitgrep ' (?<!command) ' " $ cmdstart" ' (grep|ls|sed|cd)(\s|$)' \
63+ filter_out= " test/fixtures/_longopt/grep--help.txt " gitgrep " ${ cmdstart/ |command| / |} " ' (grep|ls|sed|cd)(\s|$)' \
5764 ' invoke grep, ls, sed, and cd through "command", e.g. "command grep"'
5865
59- gitgrep ' (?<!command) ' " $ cmdstart" ' (?:awk|tail)(\s|$)' \
66+ gitgrep " ${ cmdstart/ |command| / |} " ' (?:awk|tail)(\s|$)' \
6067 ' invoke awk/tail through "_comp_{awk,tail}"'
6168
6269gitgrep ' @\([^()|$]+\)' \
@@ -65,14 +72,12 @@ gitgrep '@\([^()|$]+\)' \
6572# ------------------------------------------------------------------------------
6673# Bash pitfalls/styles/compatibilities (which are not detected by shellcheck)
6774
68- gitgrep ' <<<' ' herestrings use temp files, use some other way'
69-
70- filter_out=' ^(test/|bash_completion\.sh)' gitgrep ' \[ ' \
75+ filter_out=' test/ bash_completion.sh.in' gitgrep ' \[ ' \
7176 ' use [[ ]] instead of [ ]'
7277
7378gitgrep " $cmdstart " ' unset [^-]' ' Explicitly specify "unset -v/-f"'
7479
75- gitgrep " $cmdstart " ' ((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRECT\b)' \
80+ filter_out= " test/config/bashrc " gitgrep " $cmdstart " ' ((set|shopt)\s+[+-][a-z]+\s+posix\b|(local\s+)?POSIXLY_CORRECT\b)' \
7681 ' fiddling with posix mode breaks keybindings with some bash versions'
7782
7883gitgrep ' \$\{([^{}\n]|\{.*\})+/([^{}\n]|\{.*\})+/([^{}"\n]|\{.*\})*\$.*\}' \
0 commit comments