Skip to content

Commit 0762bbf

Browse files
committed
refine brew prefix handling
1 parent 1050d5e commit 0762bbf

2 files changed

Lines changed: 18 additions & 20 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ The following is the software that I have set as default:
294294
- watch
295295
- wget --enable-iri
296296

297-
The installer calls `brew --prefix` to detect your Homebrew prefix and appends
298-
`libexec/gnubin` directories for coreutils, gnu-sed, and grep to `.shellpaths`
299-
if they are not already present.
297+
The installer uses `brew --prefix` once to detect your Homebrew prefix and
298+
individually appends `libexec/gnubin` directories for coreutils, gnu-sed, and
299+
grep to `.shellpaths` if they are not already present.
300300

301301
## Apps
302302

install.sh

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,22 @@ brew doctor
203203
# Add GNU utilities to PATH once in .shellpaths
204204
shellpaths_file="./homedir/.shellpaths"
205205

206-
# Determine Homebrew prefix once using brew if available
207-
if command -v brew >/dev/null 2>&1; then
208-
brew_prefix="$(brew --prefix)"
209-
elif grep -qs "/opt/homebrew/bin" "$shellpaths_file"; then
210-
brew_prefix="/opt/homebrew"
211-
elif grep -qs "/usr/local/bin" "$shellpaths_file"; then
212-
brew_prefix="/usr/local"
213-
else
214-
brew_prefix=""
215-
fi
206+
# Determine Homebrew prefix once using brew
207+
brew_prefix="$(brew --prefix)"
216208

217-
if [ -n "$brew_prefix" ]; then
218-
for util in coreutils gnu-sed grep; do
219-
path="$brew_prefix/opt/$util/libexec/gnubin"
220-
if ! grep -qs "$path" "$shellpaths_file"; then
221-
echo "export PATH=\"$path:\$PATH\"" >> "$shellpaths_file"
222-
fi
223-
done
209+
# Append gnubin directories for GNU utilities if missing
210+
coreutils_path="$brew_prefix/opt/coreutils/libexec/gnubin"
211+
sed_path="$brew_prefix/opt/gnu-sed/libexec/gnubin"
212+
grep_path="$brew_prefix/opt/grep/libexec/gnubin"
213+
214+
if ! grep -qs "$coreutils_path" "$shellpaths_file"; then
215+
echo "export PATH=\"$coreutils_path:\$PATH\"" >> "$shellpaths_file"
216+
fi
217+
if ! grep -qs "$sed_path" "$shellpaths_file"; then
218+
echo "export PATH=\"$sed_path:\$PATH\"" >> "$shellpaths_file"
219+
fi
220+
if ! grep -qs "$grep_path" "$shellpaths_file"; then
221+
echo "export PATH=\"$grep_path:\$PATH\"" >> "$shellpaths_file"
224222
fi
225223

226224
# skip those GUI clients, git command-line all the way

0 commit comments

Comments
 (0)