Make compatible with both Intel and M1 Macs
dblume

dblume commited on 2023-02-16 09:26:56
Showing 1 changed files, with 7 additions and 15 deletions.

... ...
@@ -2,6 +2,10 @@
2 2
 
3 3
 if [ -f "${HOME}/.bashrc" ]; then
4 4
     if [[ $(uname -s) == Darwin* ]]; then
5
+        # Mac M1 installs into /opt/homebrew/; Intel Mac installs into /usr/local/
6
+        if [ -d "/opt/homebrew/bin/" ] && [[ ! $PATH =~ (^|:)/opt/homebrew/bin/(:|$) ]]; then
7
+            PATH+=:/opt/homebrew/bin/
8
+        fi
5 9
         command -v brew >/dev/null 2>&1 && eval "$(brew shellenv)"
6 10
     fi
7 11
     source "${HOME}/.bashrc"
... ...
@@ -18,19 +22,7 @@ if [[ $(uname -s) == Darwin* ]]; then
18 22
         alias ctags="$(brew --prefix)/bin/ctags"
19 23
     fi
20 24
     # Set default names for GNU grep, sed and find
21
-    if [[ -d "/usr/local/opt/grep/libexec/gnubin" ]]; then  # old path
22
-        prepend_to_path /usr/local/opt/grep/libexec/gnubin
23
-    elif [[ -d "/opt/homebrew/opt/grep/libexec/gnubin" ]]; then
24
-        prepend_to_path /opt/homebrew/opt/grep/libexec/gnubin
25
-    fi
26
-    if [[ -d "/usr/local/opt/gnu-sed/libexec/gnubin" ]]; then  # old path
27
-        prepend_to_path /usr/local/opt/gnu-sed/libexec/gnubin
28
-    elif [[ -d "/opt/homebrew/opt/gnu-sed/libexec/gnubin" ]]; then
29
-        prepend_to_path /opt/homebrew/opt/gnu-sed/libexec/gnubin
30
-    fi
31
-    if [[ -d "/usr/local/opt/findutils/libexec/gnubin" ]]; then  # old path
32
-        prepend_to_path /usr/local/opt/findutils/libexec/gnubin
33
-    elif [[ -d "/opt/homebrew/opt/findutils/libexec/gnubin" ]]; then
34
-        prepend_to_path /opt/homebrew/opt/findutils/libexec/gnubin
35
-    fi
25
+    prepend_to_path $HOMEBREW_PREFIX/opt/grep/libexec/gnubin
26
+    prepend_to_path $HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin
27
+    prepend_to_path $HOMEBREW_PREFIX/opt/findutils/libexec/gnubin
36 28
 fi
37 29