From 9c6cca04803c4ca9aa9f9580d0be84d50f04a6fd Mon Sep 17 00:00:00 2001 From: Nathaniel Landau Date: Fri, 12 Nov 2021 00:03:45 -0500 Subject: [PATCH] add _homebrewPath_ --- README.md | 1 + template.sh | 5 ++++- template_standalone.sh | 31 ++++++++++++++++++++++++++++--- utilities/macOS.bash | 22 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 45ac011..e519d93 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/template.sh b/template.sh index 7965c7b..1dfcc20 100755 --- a/template.sh +++ b/template.sh @@ -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 diff --git a/template_standalone.sh b/template_standalone.sh index 7ad5a1f..244e16e 100755 --- a/template_standalone.sh +++ b/template_standalone.sh @@ -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_ diff --git a/utilities/macOS.bash b/utilities/macOS.bash index a7be66c..e932bc8 100644 --- a/utilities/macOS.bash +++ b/utilities/macOS.bash @@ -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 + +}