-
Notifications
You must be signed in to change notification settings - Fork 1
/
.profile
186 lines (149 loc) · 5.79 KB
/
.profile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env bash
################################################################################
############################### IMPORTANT! #####################################
################################################################################
#
# From `man bash`:
#
# When bash is invoked as an interactive login shell, or as a non-interactive
# shell with the --login option, it first reads and executes commands from the
# file /etc/profile, if that file exists. After reading that file, it looks
# for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads
# and executes commands from the first one that exists and is readable. The
# --noprofile option may be used when the shell is started to inhibit this
# behavior.
#
################################################################################
################################################################################
################################################################################
if command -v /opt/homebrew/bin/brew >/dev/null 2>&1; then
HOMEBREW_PREFIX="$(/opt/homebrew/bin/brew --prefix)"
fi
find_latest () {
find "${1}" -maxdepth 1 -iname "${2}" 2>/dev/null | sort -Vr | head -1
}
path_append () {
if [ -d "${1}" ] && [[ ":${PATH}:" != *":${1}:"* ]]; then
export PATH="${PATH:+"${PATH}"}:${1}"
fi
}
path_prepend () {
if [ -d "${1}" ] && [[ ":${PATH}:" != *":${1}:"* ]]; then
export PATH="${1}:${PATH:+"${PATH}"}"
fi
}
# This needs to run before our appends and prepends, otherwise it will mess
# everything up.
#
# It sets up PATH based on /etc/paths and /etc/paths.d/*, and MANPATH based on
# /etc/manpaths and /etc/manpaths.d/*.
if [ -x /usr/libexec/path_helper ]; then
eval "$(/usr/libexec/path_helper -s)"
fi
# When prepending to PATH, later prepends will have higher priority.
path_prepend "/usr/local/bin"
# CMake.
path_prepend "/Applications/CMake.app/Contents/bin"
# Make.
path_prepend "$(brew --prefix)/opt/make/libexec/gnubin"
# Emacs.
latest_emacs="$(find_latest /Applications Emacs-*.app)"
path_prepend "${latest_emacs}/Contents/MacOS/bin"
# Neovim.
latest_neovim="$(find_latest /opt "nvim-*")"
path_prepend "${latest_neovim}/bin"
# MacVim.
path_prepend "/Applications/MacVim.app/Contents/bin"
# Ruby.
latest_ruby="$(find_latest "${HOME}/.gem/ruby" "*")"
path_prepend "${latest_ruby}/bin" # from `gem install --user-install $gem``
# Python 3.
# From `sudo pip3 install` or `python3 -m pip install`.
latest_python3_framework="$(find_latest /Library/Frameworks/Python.framework/Versions "3.*")"
path_prepend "${latest_python3_framework}/bin"
# From `pip3 install --user` or `python3 -m pip install --user`.
latest_python3="$(find_latest "${HOME}/Library/Python" "3.*")"
path_prepend "${latest_python3}/bin"
# LLVM.
latest_llvm="$(find_latest "${HOMEBREW_PREFIX}/opt/llvm" "*")"
if [ -d "${latest_llvm}" ]; then
path_prepend "${latest_llvm}/bin"
export LDFLAGS="-L${latest_llvm}/lib -Wl,-rpath,${latest_llvm}/lib"
export CPPFLAGS="-I${latest_llvm}/include"
fi
# curl.
latest_curl="$(find_latest "${HOMEBREW_PREFIX}/opt/curl" "*")"
if [ -d "${latest_curl}" ]; then
path_prepend "${latest_curl}/bin"
fi
# Go.
export GOROOT="/usr/local/go"
export GOPATH="${HOME}/go"
path_prepend "${GOPATH}/bin"
path_prepend "${GOROOT}/bin"
# Ghostscript.
latest_ghostscript="$(find_latest "${HOMEBREW_PREFIX}/opt/ghostscript/" "*")"
path_prepend "${latest_ghostscript}/bin"
# Rust.
# shellcheck source=/dev/null
[ -f "${HOME}/.cargo/env" ] && . "${HOME}/.cargo/env"
# GraalVM.
latest_graalvm_app="$(find_latest /Applications "GraalVM-*.app")"
if [ -d "${latest_graalvm_app}" ]; then
export GRAALVM_HOME="${latest_graalvm_app}/Contents/Home"
# GraalVM has binaries like `node`, `npm`, `javac`, `jar`, so put it at the end
# of $PATH so that they don't shadow other binaries.
path_append "${GRAALVM_HOME}/bin"
fi
# Homebrew Cask: mactex-no-gui
latest_texlive="$(find_latest /usr/local/texlive "*")"
if [ -d "${latest_texlive}" ]; then
path_prepend "${latest_texlive}/bin/x86_64-darwin"
fi
# GNU binaries without g prefix.
coreutils="${HOMEBREW_PREFIX}/opt/coreutils"
path_prepend "${coreutils}/libexec/gnubin"
coreutils_gnuman="${coreutils}/libexec/gnuman"
[ -d "${coreutils_gnuman}" ] && export MANPATH="${coreutils_gnuman}:${MANPATH}"
for gnu_program_directory in "${HOMEBREW_PREFIX}"/opt/gnu-*; do
path_prepend "${gnu_program_directory}/bin"
done
# gettext.
path_prepend "${HOMEBREW_PREFIX}/opt/gettext/bin"
# For compilers to find gettext these might need to be set:
# export LDFLAGS="-L${HOMEBREW_PREFIX}/opt/gettext/lib"
# export CPPFLAGS="-I${HOMEBREW_PREFIX}/opt/gettext/include"
# kubebuilder.
path_prepend "/usr/local/kubebuilder/bin"
# Krew.
path_prepend "${KREW_ROOT:-${HOME}/.krew}/bin"
# Bun.
path_prepend "${HOME}/.bun/bin"
# Emacs ansi-term doesn't set locale env variables.
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LC_CTYPE=en_US.UTF-8
# Completion.
for completion_script in "$(brew --prefix)"/etc/bash_completion.d/*; do
# shellcheck source=/dev/null
[ -f "${completion_script}" ] && . "${completion_script}"
done
git_completions_bash="/usr/local/git/contrib/completion/git-completion.bash"
# shellcheck source=/dev/null
[ -f "${git_completions_bash}" ] && . "${git_completions_bash}"
# Aliases.
# shellcheck source=/dev/null
[ -f .aliases ] && . .aliases
# Yarn.
path_prepend "${HOME}/.yarn/bin"
path_prepend "${HOME}/.config/yarn/global/node_modules/.bin"
# .NET
# export DOTNET_ROOT="/usr/local/share/dotnet/host"
# This prepends the Homebrew binary path to $PATH, so running it last.
if command -v /opt/homebrew/bin/brew >/dev/null 2>&1; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
# Mimic XDG base directory specification.
# https://pkg.go.dev/os#UserCacheDir
export XDG_CACHE_HOME="${HOME}/Library/Caches"
export XDG_CONFIG_HOME="${HOME}/Library/Application Support"