@@ -7,16 +7,62 @@ if ! [[ "$0" =~ scripts/lint.sh ]]; then
77 exit 255
88fi
99
10- # The -P option is not supported by the grep version installed by
11- # default on macos. Since `-o errexit` is ignored in an if
12- # conditional, triggering the problem here ensures script failure when
13- # using an unsupported version of grep.
14- grep -P ' lint.sh' scripts/lint.sh & > /dev/null || (
10+ # Darwin-specific environment handling: ensure Bash 4+ and GNU grep availability.
11+ function handle_darwin_environment_specifics {
12+ # Re-exec with Homebrew bash when system bash is < 4 (macOS default 3.2)
13+ if ! { test -n " ${BASH_VERSINFO:- } " && [ " ${BASH_VERSINFO[0]} " -ge 4 ]; }; then
14+ for _brew_bash in " /opt/homebrew/bin/bash" " /usr/local/bin/bash" ; do
15+ if [[ -x " ${_brew_bash} " ]]; then
16+ exec " ${_brew_bash} " " $0 " " $@ "
17+ fi
18+ done
19+ echo >&2 " error: This script requires bash >= 4. On macOS, install with: brew install bash"
20+ echo >&2 " Then ensure Homebrew bash is used first in PATH or re-run via: /opt/homebrew/bin/bash scripts/lint.sh"
21+ exit 255
22+ fi
23+
24+ # Prefer ggrep when available; make a shim so plain `grep` resolves to it
25+ if command -v ggrep > /dev/null 2>&1 ; then
26+ if ggrep -P ' lint.sh' scripts/lint.sh & > /dev/null; then
27+ _gnu_grep_shim_dir=" $( mktemp -d) "
28+ ln -s " $( command -v ggrep) " " ${_gnu_grep_shim_dir} /grep" 2> /dev/null || true
29+ export PATH=" ${_gnu_grep_shim_dir} :$PATH "
30+ fi
31+ fi
32+
33+ # Try Homebrew gnubin via brew and well-known locations
34+ if command -v brew > /dev/null 2>&1 ; then
35+ local gnubin_dir
36+ gnubin_dir=" $( brew --prefix grep 2> /dev/null) /libexec/gnubin"
37+ if [[ -d " $gnubin_dir " ]]; then
38+ export PATH=" $gnubin_dir :$PATH "
39+ fi
40+ fi
41+ for d in \
42+ " /opt/homebrew/opt/grep/libexec/gnubin" \
43+ " /usr/local/opt/grep/libexec/gnubin" ; do
44+ if [[ -d " $d " ]]; then
45+ export PATH=" $d :$PATH "
46+ fi
47+ done
48+ }
49+
50+ # Run Darwin adjustments early if applicable
51+ if [[ " $( uname -s) " == " Darwin" ]]; then
52+ handle_darwin_environment_specifics " $@ "
53+ fi
54+
55+ # Final probe; fail hard if still unsupported
56+ if ! grep -P ' lint.sh' scripts/lint.sh & > /dev/null; then
1557 echo >&2 " error: This script requires a recent version of gnu grep."
16- echo >&2 " On macos, gnu grep can be installed with 'brew install grep'."
17- echo >&2 " It will also be necessary to ensure that gnu grep is available in the path."
58+ if [[ " $( uname -s) " == " Darwin" ]]; then
59+ echo >&2 " On macOS, install with: brew install grep"
60+ echo >&2 " Ensure gnubin is on PATH, e.g.:"
61+ echo >&2 " export PATH=\" /opt/homebrew/opt/grep/libexec/gnubin:\$ PATH\" # Apple Silicon"
62+ echo >&2 " export PATH=\" /usr/local/opt/grep/libexec/gnubin:\$ PATH\" # Intel"
63+ fi
1864 exit 255
19- )
65+ fi
2066
2167# Read excluded directories into arrays
2268DEFAULT_FILES=()
0 commit comments