From 9930bbc009af2d9e6e2cbdb3f3bf59ba70ab1bf5 Mon Sep 17 00:00:00 2001 From: Jonny Barnes Date: Sat, 8 Aug 2026 11:53:40 +0100 Subject: [PATCH] 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) --- zshrc.zsh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/zshrc.zsh b/zshrc.zsh index dfd99b8..2d683f8 100644 --- a/zshrc.zsh +++ b/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"