Stop shadowing BSD coreutils with GNU versions on PATH
Prepending the coreutils/findutils/gnu-sed/grep gnubin dirs put GNU stat, date, sed, grep and find on the PATH under their un-prefixed names, which silently breaks any script written against the macOS versions. Portable scripts typically probe BSD-first and fall back to GNU, so the BSD probe succeeds against a GNU binary that means something else entirely and the fallback never fires. The Claude Code statusline was a live example: it reads a cache file's mtime with `stat -f %m`, which GNU stat parses as a *filesystem* format string. That emits a multi-line blob, the following arithmetic hits a syntax error, and because an arithmetic error aborts the shell the enclosing function returned early - so the git branch segment silently vanished on every warm-cache render. Its `date -j -r` reset timestamps failed the same way. Homebrew installs the g-prefixed variants into $HOMEBREW_PREFIX/bin regardless, so gstat / gdate / gsed / ggrep / gfind still give GNU behaviour on demand. Note BSD sed needs `sed -i ''` rather than `sed -i`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8cc69aa6f3
commit
9930bbc009
1 changed files with 5 additions and 5 deletions
10
zshrc.zsh
10
zshrc.zsh
|
|
@ -27,11 +27,11 @@ export GOPATH=$HOME/go
|
|||
|
||||
# Homebrew-managed tools
|
||||
if (( ${+commands[brew]} )); then
|
||||
# GNU functions - prepend so they override any system installed versions
|
||||
export PATH="$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin:$PATH"
|
||||
export PATH="$HOMEBREW_PREFIX/opt/findutils/libexec/gnubin:$PATH"
|
||||
export PATH="$HOMEBREW_PREFIX/opt/gnu-sed/libexec/gnubin:$PATH"
|
||||
export PATH="$HOMEBREW_PREFIX/opt/grep/libexec/gnubin:$PATH"
|
||||
# GNU functions are NOT put on the PATH under their un-prefixed names.
|
||||
# Shadowing BSD stat/date/sed/grep silently breaks scripts that expect the
|
||||
# macOS versions (portable scripts probe with `stat -f` / `date -j` first).
|
||||
# Homebrew still installs the g-prefixed variants in $HOMEBREW_PREFIX/bin,
|
||||
# so use gstat / gdate / gsed / ggrep / gfind when you want GNU behaviour.
|
||||
|
||||
# Homebrew cURL if we have it
|
||||
test -d $HOMEBREW_PREFIX/opt/curl && export PATH="$HOMEBREW_PREFIX/opt/curl/bin:$PATH"
|
||||
|
|
|
|||
Loading…
Reference in a new issue