From 4695cb721e05d8ce838f712045a296546b5eae2e Mon Sep 17 00:00:00 2001 From: David Mejorado Date: Sun, 23 Feb 2025 13:03:24 -0800 Subject: [PATCH 1/2] Don't assume brew is available in the system All we care about is that GNU grep is available, which could've been installed in a number of ways, not just via Homebrew. --- lib/helpers.sh | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/helpers.sh b/lib/helpers.sh index 0f0de24..a86a3e2 100755 --- a/lib/helpers.sh +++ b/lib/helpers.sh @@ -147,13 +147,16 @@ function error_and_proceed() { export -f error_and_proceed; function check_dependencies() { - if [[ $(uname) == 'Darwin' ]] && [ $(which brew) ]; then - if ! [ $(which ggrep) ]; then - log 'error' 'A metaphysical dichotomy has caused this unit to overload and shut down. GNU Grep is a requirement and your Mac does not have it. Consider "brew install grep"'; + if [[ $(uname) == 'Darwin' ]]; then + # If installed through brew, it will be available as `ggrep`, so we alias it to `grep` + if command -v ggrep >/dev/null 2>&1; then + shopt -s expand_aliases; + alias grep=ggrep; fi; - shopt -s expand_aliases; - alias grep=ggrep; + if ! grep --version 2>&1 | grep -q "GNU grep"; then + log 'error' 'GNU Grep is a requirement and your Mac does not have it. Consider installing it with `brew install grep` or `nix profile install nixpkgs#gnugrep`'; + fi; fi; }; export -f check_dependencies; From d57fdd50b49a1c5852ce51f6f2ca1f3b15c83a60 Mon Sep 17 00:00:00 2001 From: David Mejorado Date: Fri, 4 Jul 2025 13:08:52 -0700 Subject: [PATCH 2/2] Fix brew-specific check When we find a brew-installed grep, we create an alias from ggrep to grep, but an alias can't be defined and used in the same parsing unit, so we exit early instead. See: https://www.shellcheck.net/wiki/SC2262 --- lib/helpers.sh | 4 ++++ test/install_deps.sh | 3 +++ 2 files changed, 7 insertions(+) diff --git a/lib/helpers.sh b/lib/helpers.sh index a86a3e2..933a283 100755 --- a/lib/helpers.sh +++ b/lib/helpers.sh @@ -152,6 +152,10 @@ function check_dependencies() { if command -v ggrep >/dev/null 2>&1; then shopt -s expand_aliases; alias grep=ggrep; + + # The alias can't be defined and used in the same parsing unit. But + # since we know the correct package is installed, we can exit early. + return; fi; if ! grep --version 2>&1 | grep -q "GNU grep"; then diff --git a/test/install_deps.sh b/test/install_deps.sh index f1bd2d6..30333c0 100755 --- a/test/install_deps.sh +++ b/test/install_deps.sh @@ -3,4 +3,7 @@ set -uo pipefail; if [[ $(uname) == 'Darwin' ]] && [ $(which brew) ]; then brew install grep; + if [[ -n ${GITHUB_PATH+x} ]]; then + echo "/opt/homebrew/opt/grep/libexec/gnubin" >> $GITHUB_PATH + fi fi;