From: Alexander Barton Date: Wed, 21 Sep 2022 21:19:09 +0000 (+0200) Subject: homebrew: brew() function: Test permissions on the repository X-Git-Url: https://arthur.ath.cx/gitweb/?a=commitdiff_plain;h=f80700806fb21f784ca5f7c45246016a793b7f7a;p=ax-zsh.git homebrew: brew() function: Test permissions on the repository Don't test it on the "prefix", because permissions on this directory can be more restrictive (which could be fine ...). --- diff --git a/plugins/homebrew/homebrew.zshrc b/plugins/homebrew/homebrew.zshrc index 34f0b69..8759da5 100644 --- a/plugins/homebrew/homebrew.zshrc +++ b/plugins/homebrew/homebrew.zshrc @@ -31,9 +31,11 @@ function brew() { return 101 fi - brew_prefix=$("$real_brew_cmd" --prefix) || return 102 + if [[ -z "$HOMEBREW_REPOSITORY" ]]; then + eval "$("$real_brew_cmd" shellenv)" + fi - if [[ $(/bin/ls -ldn "$brew_prefix" | awk '{print $3}') -eq $UID ]]; then + if [[ $(/bin/ls -ldn "$HOMEBREW_REPOSITORY" | awk '{print $3}') -eq $UID ]]; then # We are the owner of the Homebrew installation. ( [[ $# -eq 0 && -t 1 ]] \ @@ -48,8 +50,8 @@ function brew() { priv_exec="umask 0022 || exit 103; \"$real_brew_cmd\" $*" ( cd /tmp - user="$(/bin/ls -ld "$brew_prefix" | awk '{print $3}')" - group="$(/bin/ls -ld "$brew_prefix" | awk '{print $4}')" + user="$(/bin/ls -ld "$HOMEBREW_REPOSITORY" | awk '{print $3}')" + group="$(/bin/ls -ld "$HOMEBREW_REPOSITORY" | awk '{print $4}')" [[ $# -eq 0 && -t 1 ]] \ && echo "Running \"$real_brew_cmd\" as user \"$user:$group\" ..." sudo -u "$user" -g "$group" -- sh -c "$priv_exec"