From 2c5365343ea8452d81ee793a4e860f9bf0e7f23e Mon Sep 17 00:00:00 2001 From: Tri Vo Khac Date: Tue, 15 Sep 2026 14:35:19 +0700 Subject: [PATCH] perf(zsh): skip brew --prefix on startup and guard empty XDG_BIN_HOME --- zsh/.config/zsh/config/bin.zsh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/zsh/.config/zsh/config/bin.zsh b/zsh/.config/zsh/config/bin.zsh index 6282424..160cd3d 100644 --- a/zsh/.config/zsh/config/bin.zsh +++ b/zsh/.config/zsh/config/bin.zsh @@ -1,6 +1,11 @@ #!/usr/bin/env zsh local brew_prefix="${HOMEBREW_PREFIX:-}" +# `brew --prefix` costs ~12 ms because it runs Ruby. Check the standard +# Apple Silicon location first, then fall back for anything else. +if [[ -z "$brew_prefix" ]]; then + [[ -x /opt/homebrew/bin/brew ]] && brew_prefix=/opt/homebrew +fi if [[ -z "$brew_prefix" ]] && command -v brew >/dev/null 2>&1; then brew_prefix="$(brew --prefix 2>/dev/null)" fi @@ -16,7 +21,7 @@ if [[ -n "$brew_prefix" ]]; then "grep" ) - if mkdir -p "$XDG_BIN_HOME"; then + if [[ -n "$XDG_BIN_HOME" ]] && mkdir -p "$XDG_BIN_HOME"; then for tool in $gnu_tools; do gnubin="$brew_prefix/opt/$tool/libexec/gnubin" if [[ -d "$gnubin" ]]; then