]> arthur.barton.de Git - ax-zsh.git/commitdiff
homebrew: brew() function: Test permissions on the repository
authorAlexander Barton <alex@barton.de>
Wed, 21 Sep 2022 21:19:09 +0000 (23:19 +0200)
committerAlexander Barton <alex@barton.de>
Wed, 21 Sep 2022 21:19:15 +0000 (23:19 +0200)
Don't test it on the "prefix", because permissions on this directory can be
more restrictive (which could be fine ...).

plugins/homebrew/homebrew.zshrc

index 34f0b69a4043b8409de04190a3773852f4ce3b46..8759da50fbe4e4a10324b47442c64e9333900fac 100644 (file)
@@ -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"