From ddf3de5a804a4af56f381bccb978f41d8724ee29 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Mon, 4 Mar 2024 13:58:20 -0800 Subject: [PATCH] [zsh] Implement a homebrew-prefix function and use it when setting up fpath # Conflicts: # zshrc --- zsh/func/homebrew-prefix | 19 +++++++++++++++++++ zsh/func/init_rc_fpath_darwin | 5 +++-- zshrc | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 zsh/func/homebrew-prefix diff --git a/zsh/func/homebrew-prefix b/zsh/func/homebrew-prefix new file mode 100644 index 0000000..c05c68d --- /dev/null +++ b/zsh/func/homebrew-prefix @@ -0,0 +1,19 @@ +#!/usr/bin/env zsh + +autoload binary_exists + +function homebrew-prefix +{ + if [[ -e "$SYSTEM_PARAMETERS_FILE" ]] && binary_exists jq; then + jq .parameters.homebrew_prefix.value "$SYSTEM_PARAMETERS_FILE" + return + fi + + if ! binary_exists brew; then + return + fi + + brew --prefix +} + +homebrew-prefix "$@" diff --git a/zsh/func/init_rc_fpath_darwin b/zsh/func/init_rc_fpath_darwin index 53249e8..5ee1a3b 100644 --- a/zsh/func/init_rc_fpath_darwin +++ b/zsh/func/init_rc_fpath_darwin @@ -1,11 +1,12 @@ # Eryn Wells -autoload -Uz binary_exists +autoload binary_exists +autoload homebrew-prefix function init_rc_fpath_darwin { if binary_exists brew; then - local brew_fpath="$(brew --prefix)/share/zsh/site-functions" + local brew_fpath="$(homebrew-prefix)/share/zsh/site-functions" if [[ -d "$brew_fpath" ]]; then fpath+=($brew_fpath) fi diff --git a/zshrc b/zshrc index ae5e58d..358f8be 100644 --- a/zshrc +++ b/zshrc @@ -21,4 +21,4 @@ autoload -Uz nethack autoload -Uz pw autoload -Uz up autoload -Uz vi -autoload -Uz open-xcode +autoload -Uz homebrew-prefix