Last active
February 10, 2023 19:02
-
-
Save leogdion/4906d6d1ea111a6b078132ef4e7fd7e4 to your computer and use it in GitHub Desktop.
Detect Brew Prefix If Needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BREW_PATH="$(which brew)" | |
BREW_PATH_RESULT=$? | |
if [[ $BREW_PATH_RESULT -ne 0 ]] || [[ -z "$BREW_PATH" ]]; then | |
echo "It looks like Homebrew is not already installed." | |
echo "Finding path where it will be..." | |
arch="$(arch)" # -i is only linux, -m is linux and apple | |
if [[ "$arch" = i386 ]]; then | |
echo "You are on an Intel machine. So.." | |
BIN_PREFIX="/usr/local/bin/" | |
elif [[ "$arch" = arm64 ]]; then | |
echo "You are on an Apple Silicon machine. So .." | |
BIN_PREFIX="/opt/homebrew/bin/" | |
else | |
echo "Unknown CPU Architecture: $arch" | |
fi | |
elif [[ $BREW_PATH_RESULT -eq 0 ]]; then | |
echo "It looks like Homebrew is already installed and in your PATH." | |
echo "Therefore we won't use a prefix." | |
ACTUAL_BIN_PATH="$(dirname $BREW_PATH)" | |
fi | |
echo "" | |
echo "Will use bin prefix for Homebrew commands:" | |
echo -e " ${BIN_PREFIX-\033[0;32mnone\033[0m}" | |
echo "Current actual path to Homebrew commands:" | |
echo -e " ${ACTUAL_BIN_PATH-\033[0;31not installed\033[0m}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment