Skip to content

Commit 46c7032

Browse files
committedMay 20, 2023
Fix hardcoded Homebrew prefix
The Homebrew prefix was hardcoded to /usr/local in ~/.bashrc and ~/.bash_profile. However, on newer Apple chip computers, the default prefix is /opt/homebrew (see [1]). These hardcoded prefixes have been replaced by $(brew --prefix) to determine the prefix dynamically. Also, unnecessary PATH and variable settings have been outcommented in ~/.bash_profile. [1] https://docs.brew.sh/FAQ#why-should-i-install-homebrew-in-the-default-location
1 parent edcea77 commit 46c7032

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed
 

‎.bash_profile

+28-22
Original file line numberDiff line numberDiff line change
@@ -21,44 +21,50 @@ if [[ "$OSTYPE" =~ darwin ]]; then
2121
export HISTSIZE=5000
2222
export HISTFILESIZE=5000
2323

24+
# Homebrew
25+
# Correct prefix depends on chip architecture (Intel or Apple).
26+
# See https://docs.brew.sh/FAQ#why-should-i-install-homebrew-in-the-default-location
27+
eval $(/opt/homebrew/bin/brew shellenv)
28+
#eval $(/usr/local/bin/brew shellenv)
29+
export HOMEBREW_NO_AUTO_UPDATE=1
30+
2431
# Java
2532
#export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.3.jdk/Contents/Home
26-
export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
27-
export JUNIT_HOME=$JAVA_HOME/lib
28-
export GROOVY_HOME=/usr/local/opt/groovy/libexec
33+
#export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home
34+
#export JUNIT_HOME=$JAVA_HOME/lib
35+
#export GROOVY_HOME=/usr/local/opt/groovy/libexec
2936

3037
# Misc
3138
export d=~/Desktop
32-
export tex_home=/usr/local/texlive
39+
#export tex_home=/usr/local/texlive
3340
export fonts_user=~/Library/Fonts
3441
export fonts_local=/Library/Fonts
3542
export fonts_system=/System/Library/Fonts
36-
export PYTHONSTARTUP=~/.python
37-
export GOPATH=$HOME/go
38-
export HOMEBREW_NO_AUTO_UPDATE=1
39-
alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
43+
#export PYTHONSTARTUP=~/.python
44+
#export GOPATH=$HOME/go
45+
#alias chrome="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
4046

4147
# PATH
42-
path_append "$HOME/bin"
43-
path_append "/usr/local/sbin"
44-
path_append "$HOME/.krew/bin"
45-
path_append "$HOME/.kubectl-plugins"
46-
path_append "$HOME/google-cloud-sdk/bin"
47-
path_append "$HOME/platform-tools"
48-
path_append "$(go env GOPATH)/bin"
49-
path_prepend /usr/local/opt/ruby/bin
50-
path_prepend /usr/local/lib/ruby/gems/2.6.0/bin
48+
#path_append "$HOME/bin"
49+
#path_append "/usr/local/sbin"
50+
#path_append "$HOME/.krew/bin"
51+
#path_append "$HOME/.kubectl-plugins"
52+
#path_append "$HOME/google-cloud-sdk/bin"
53+
#path_append "$HOME/platform-tools"
54+
#path_append "$(go env GOPATH)/bin"
55+
#path_prepend /usr/local/opt/ruby/bin
56+
#path_prepend /usr/local/lib/ruby/gems/2.6.0/bin
5157
# GNU Make
52-
path_prepend /usr/local/opt/make/libexec/gnubin
58+
#path_prepend /usr/local/opt/make/libexec/gnubin
5359
# Homebrew version of curl
54-
path_prepend /usr/local/opt/curl/bin
60+
#path_prepend /usr/local/opt/curl/bin
5561
# sketchtool
56-
path_append /Applications/Sketch.app/Contents/MacOS
62+
#path_append /Applications/Sketch.app/Contents/MacOS
5763
# Added by serverless binary installer
58-
export PATH="$HOME/.serverless/bin:$PATH"
64+
#export PATH="$HOME/.serverless/bin:$PATH"
5965

6066
# Command completion
61-
complete -C /usr/local/bin/packer packer
67+
#complete -C /usr/local/bin/packer packer
6268

6369
fi
6470

‎.bashrc

+16-6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ ensure() {
6969
which -s "$1" || { echo "Error: '$1' not installed."; return 1; }
7070
}
7171

72+
# Test whether a Homebrew formula or cask, respectively, is installed.
73+
is-homebrew-formula-installed() {
74+
brew ls --versions "$1" >/dev/null
75+
}
76+
is-homebrew-cask-installed() {
77+
brew ls --cask --versions "$1" >/dev/null
78+
}
79+
7280
# Capitalise the first letter of a string
7381
capitalize () {
7482
echo $(echo "${1:0:1}" | tr '[:lower:]' '[:upper:]')"${1:1}"
@@ -311,9 +319,9 @@ __dump_history() {
311319
#------------------------------------------------------------------------------#
312320

313321
if is-mac ; then
314-
source /usr/local/etc/profile.d/bash_completion.sh
322+
source $(brew --prefix)/etc/profile.d/bash_completion.sh
315323
# Source completion scripts of Homebrew formulas
316-
for f in /usr/local/etc/bash_completion.d/*; do
324+
for f in $(brew --prefix)/etc/bash_completion.d/*; do
317325
source "$f"
318326
done
319327
fi
@@ -1123,7 +1131,7 @@ sm() {
11231131
smp && smd "$1"
11241132
}
11251133

1126-
complete -C /usr/local/bin/aws_completer aws
1134+
complete -C $(brew --prefix)/bin/aws_completer aws
11271135

11281136
#------------------------------------------------------------------------------#
11291137
# Azure
@@ -1656,7 +1664,7 @@ prometheus-clean() {
16561664
#------------------------------------------------------------------------------#
16571665

16581666
# Terraform autocompletion (installed with terraform --install-autocomplete)
1659-
complete -C /usr/local/bin/terraform terraform
1667+
complete -C $(brew --prefix)/bin/terraform terraform
16601668

16611669
alias tf=terraform
16621670
#complete -F _complete_alias t
@@ -1671,8 +1679,10 @@ alias tfdd='terraform destroy --auto-approve'
16711679
#------------------------------------------------------------------------------#
16721680
if is-mac; then
16731681

1674-
# Use Vim installed by Homebrew
1675-
alias vim=/usr/local/bin/vim
1682+
# Use Homebrew Vim by default
1683+
if is-homebrew-formula-installed vim; then
1684+
alias vim=$(brew --prefix)/bin/vim
1685+
fi
16761686

16771687
# Recursively delete all .DS_Store files in the current directory
16781688
alias rmds='find . -type f \( -name .DS_Store -or -name ._.DS_Store \) -delete'

0 commit comments

Comments
 (0)
Failed to load comments.