From 5017eca505873641bc89d314230e880902f0fcf0 Mon Sep 17 00:00:00 2001 From: eientei95 Date: Sun, 25 May 2025 10:46:56 +1200 Subject: [PATCH] feat(grep): Use ggrep via Homebrew if it is installed --- lib/grep.zsh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/grep.zsh b/lib/grep.zsh index 1a70de7e5..158dcd071 100644 --- a/lib/grep.zsh +++ b/lib/grep.zsh @@ -5,8 +5,14 @@ __GREP_ALIAS_CACHES=("$__GREP_CACHE_FILE"(Nm-1)) if [[ -n "$__GREP_ALIAS_CACHES" ]]; then source "$__GREP_CACHE_FILE" else + # If ggrep via Homebrew is not available, use system grep + if [[ -n "$HOMEBREW_PREFIX" && -x "$HOMEBREW_PREFIX/bin/ggrep" ]]; then + GREP="ggrep" + else + GREP="grep" + fi grep-flags-available() { - command grep "$@" "" &>/dev/null <<< "" + command $GREP "$@" "" &>/dev/null <<< "" } # Ignore these folders (if the necessary grep flags are available) @@ -23,9 +29,9 @@ else if [[ -n "$GREP_OPTIONS" ]]; then # export grep, egrep and fgrep settings - alias grep="grep $GREP_OPTIONS" - alias egrep="grep -E" - alias fgrep="grep -F" + alias grep="$GREP $GREP_OPTIONS" + alias egrep="$GREP -E" + alias fgrep="$GREP -F" # write to cache file if cache directory is writable if [[ -w "$ZSH_CACHE_DIR" ]]; then @@ -34,7 +40,7 @@ else fi # Clean up - unset GREP_OPTIONS EXC_FOLDERS + unset GREP GREP_OPTIONS EXC_FOLDERS unfunction grep-flags-available fi