Skip to content

Don't assume brew is available in the system #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions lib/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,20 @@ 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;

# 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;

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;
Expand Down
3 changes: 3 additions & 0 deletions test/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;