add _homebrewPath_

This commit is contained in:
Nathaniel Landau
2021-11-12 00:03:45 -05:00
parent bbe2a9e0d4
commit 9c6cca0480
4 changed files with 55 additions and 4 deletions

View File

@@ -247,6 +247,7 @@ Functions useful when writing scripts to be run on macOS
- **`_guiInput_`** Ask for user input using a Mac dialog box
- **`_haveScriptableFinder_`** Determine whether we can script the Finder or not
- **`_homebrewPath_`** Adds Homebrew bin directory to PATH
- **`_useGNUUtils_`** Add GNU utilities to PATH to allow consistent use of sed/grep/tar/etc. on MacOS
## misc.bash

View File

@@ -359,7 +359,10 @@ _parseOptions_ "$@"
# Acquire script lock
# _acquireScriptLock_
# Source GNU utilities for use on MacOS
# Add Homebrew bin directory to PATH (MacOS)
# _homebrewPath_
# Source GNU utilities from Homebrew (MacOS)
# _useGNUutils_
# Run the main logic script

View File

@@ -350,6 +350,28 @@ _makeTempDir_() {
debug "\$TMP_DIR=${TMP_DIR}"
}
_homebrewPath_() {
# DESC:
# Add homebrew bin dir to PATH
# ARGS:
# None
# OUTS:
# 0 if successful
# 1 if unsuccessful
# PATH: Adds homebrew bin directory to PATH
# USAGE:
# # if ! _homebrewPath_; then exit 1; fi
! declare -f "_setPATH_" &>/dev/null && fatal "${FUNCNAME[0]} needs function _setPATH_"
if _setPATH_ "/usr/local/bin" "/opt/homebrew/bin"; then
return 0
else
return 1
fi
}
# shellcheck disable=SC2120
_acquireScriptLock_() {
# DESC:
@@ -391,7 +413,7 @@ _setPATH_() {
# ARGS:
# $@ - One or more paths
# OPTS:
# -x - Fail if directories are not found
# -x Fail if directories are not found
# OUTS:
# 0: Success
# 1: Failure
@@ -637,8 +659,11 @@ _parseOptions_ "$@"
# Acquire script lock
# _acquireScriptLock_
# Source GNU utilities for use on MacOS
_useGNUutils_
# Add Homebrew bin directory to PATH (MacOS)
# _homebrewPath_
# Source GNU utilities from Homebrew (MacOS)
# _useGNUutils_
# Run the main logic script
_mainScript_

View File

@@ -81,3 +81,25 @@ _useGNUutils_() {
fi
}
_homebrewPath_() {
# DESC:
# Add homebrew bin dir to PATH
# ARGS:
# None
# OUTS:
# 0 if successful
# 1 if unsuccessful
# PATH: Adds homebrew bin directory to PATH
# USAGE:
# # if ! _homebrewPath_; then exit 1; fi
! declare -f "_setPATH_" &>/dev/null && fatal "${FUNCNAME[0]} needs function _setPATH_"
if _setPATH_ "/usr/local/bin" "/opt/homebrew/bin"; then
return 0
else
return 1
fi
}