From 2f9bf5f047ccc86b3d8f609265bd1af0981580f8 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 24 Aug 2016 10:55:46 +0100 Subject: [PATCH] bin/brew: split up brew file symlink check. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will enable this code to be reused in a future commit and makes it more obvious what’s being done. --- bin/brew | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/bin/brew b/bin/brew index f73ba14e14..167a09756b 100755 --- a/bin/brew +++ b/bin/brew @@ -5,6 +5,13 @@ quiet_cd() { cd "$@" >/dev/null } +symlink_target_directory() { + local target="$(readlink "$1")" + local target_dirname="$(dirname "$target")" + local directory="$2" + quiet_cd "$directory" && quiet_cd "$target_dirname" && pwd -P +} + BREW_FILE_DIRECTORY="$(quiet_cd "${0%/*}/" && pwd -P)" HOMEBREW_BREW_FILE="${BREW_FILE_DIRECTORY%/}/${0##*/}" HOMEBREW_PREFIX="${HOMEBREW_BREW_FILE%/*/*}" @@ -17,12 +24,10 @@ fi HOMEBREW_REPOSITORY="$HOMEBREW_PREFIX" +# Resolve the bin/brew symlink to find Homebrew's repository if [[ -L "$HOMEBREW_BREW_FILE" ]] then - BREW_SYMLINK="$(readlink "$HOMEBREW_BREW_FILE")" - BREW_SYMLINK_DIRECTORY="$(dirname "$BREW_SYMLINK")" - BREW_FILE_DIRECTORY="$(quiet_cd "$BREW_FILE_DIRECTORY" && - quiet_cd "$BREW_SYMLINK_DIRECTORY" && pwd -P)" + BREW_FILE_DIRECTORY="$(symlink_target_directory "$HOMEBREW_BREW_FILE" "$BREW_FILE_DIRECTORY")" HOMEBREW_REPOSITORY="${BREW_FILE_DIRECTORY%/*}" fi