]> arthur.barton.de Git - ax-zsh.git/commitdiff
homebrew: No longer provide a "brew" wrapper function
authorAlexander Barton <alex@barton.de>
Tue, 20 Jun 2023 15:24:22 +0000 (17:24 +0200)
committerAlexander Barton <alex@barton.de>
Tue, 20 Jun 2023 15:24:22 +0000 (17:24 +0200)
Don't provide a "brew" wrapper shell function (which was not available
for other commands), look for the "real" brew command instead and use it
with the "shellenv" subcommand to properly setup the environment.

This reverts c27ca78.

plugins/homebrew/homebrew.zprofile
plugins/homebrew/homebrew.zshrc [deleted file]

index 84cb740d0347bfcc6f29dafe79eae2d680b2d814..df0c30c6aeb08b4b507973409bf55948466f786e 100644 (file)
@@ -1,10 +1,20 @@
 # AX-ZSH: Alex' Modular ZSH Configuration
 # homebrew.zprofile -- Setup Homebrew Package Manager
 
-# Make sure that "brew(1)" is installed
-(( $+commands[brew] )) || return 1
+# Look for the "brew(1) command ...
+for brew_cmd (
+       /home/linuxbrew/.linuxbrew/bin/brew
+       /opt/homebrew/bin/brew
+       /usr/local/bin/brew
+); do
+       [[ -x "$brew_cmd" ]] && break
+done
+if [[ ! -x "$brew_cmd" ]]; then
+       unset brew_cmd
+       return 1
+fi
 
-eval "$(brew shellenv)"
+eval "$("$brew_cmd" shellenv)"
 
 for dir (
        "$HOMEBREW_PREFIX/share/zsh-completions"
@@ -13,6 +23,6 @@ for dir (
        [[ -d "$dir" ]] && axzsh_fpath+=("$dir")
 
 done
-unset dir
+unset dir brew_cmd
 
 return 0
diff --git a/plugins/homebrew/homebrew.zshrc b/plugins/homebrew/homebrew.zshrc
deleted file mode 100644 (file)
index 379eae9..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-# AX-ZSH: Alex' Modular ZSH Configuration
-# homebrew.zshrc -- Setup Homebrew Package Manager
-
-# Make sure that "brew(1)" is installed
-(( $+commands[brew] )) || return 1
-
-if [[ -n "$AXZSH_PLUGIN_CHECK" ]]; then
-       # Make sure brew command is working
-       brew --version >/dev/null 2>&1 || return 1
-fi
-
-function brew() {
-       # This wrapper function for the brew(1) command does the following:
-       # - Detect the location of the "real" brew(1) command.
-       # - Change user and group when the Homebrew installation is owned by a
-       #   different user (to preserve sane file permissions).
-       # - Set a relaxed umask(1) so that other users can use software
-       #   installed by Homebrew.
-       # - Call the "real" brew(1) command.
-
-       if [[ -x /home/linuxbrew/.linuxbrew/bin/brew ]]; then
-               real_brew_cmd="/home/linuxbrew/.linuxbrew/bin/brew"
-       elif [[ -x /opt/homebrew/bin/brew ]]; then
-               real_brew_cmd="/opt/homebrew/bin/brew"
-       elif [[ -x /usr/local/bin/brew ]]; then
-               real_brew_cmd="/usr/local/bin/brew"
-       else
-               if [[ "$1" != "shellenv" && "$1" != "--prefix" ]]; then
-                       echo "Oops, real \"brew\" command not found!? [for \"$1\"]" >&2
-               fi
-               return 101
-       fi
-
-       if [[ -z "$HOMEBREW_REPOSITORY" ]]; then
-               echo "Oops, \"HOMEBREW_REPOSITORY\" not set? Trying to fix ..." >&2
-               eval "$("$real_brew_cmd" shellenv)"
-       fi
-
-       if [[ $(/bin/ls -ldn "$HOMEBREW_REPOSITORY" | awk '{print $3}') -eq $UID ]]; then
-               # We are the owner of the Homebrew installation.
-               (
-                       [[ $# -eq 0 && -t 1 ]] && echo "Running \"$real_brew_cmd\" ..."
-                       umask 0022 || return 102
-                       "$real_brew_cmd" "$@"
-               )
-       else
-               # We are a different user than the owner of the Homebrew
-               # installation. So we need to change the user when running the
-               # real "brew" command!
-               priv_exec="eval \$("$real_brew_cmd" shellenv) || exit 103; umask 0022 || exit 104; \"$real_brew_cmd\" $*"
-               (
-                       cd /tmp
-                       user="$(/bin/ls -ld "$HOMEBREW_REPOSITORY" | awk '{print $3}')"
-                       group="$(/bin/ls -ld "$HOMEBREW_REPOSITORY" | awk '{print $4}')"
-                       if [[ $# -eq 0 || "$1" = "doctor" || "$1" = "dr" ]]; then
-                               echo "Running \"$real_brew_cmd\" as user \"$user:$group\" ..."
-                       fi
-                       sudo -u "$user" -g "$group" -- sh -c "$priv_exec"
-               )
-       fi
-       return $?
-}