From d77d510ce9a6e59ef9e5a446abfbf769bc544ff9 Mon Sep 17 00:00:00 2001 From: XuehaiPan Date: Wed, 15 Sep 2021 01:45:21 +0800 Subject: [PATCH 1/3] brew.sh: alias `which` as `type -P` --- Library/Homebrew/brew.sh | 6 ++++++ Library/Homebrew/utils/ruby.sh | 33 ++++++++------------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 13d3c3a21c..bd4cb09cb5 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -137,6 +137,12 @@ git() { "${HOMEBREW_LIBRARY}/Homebrew/shims/scm/git" "$@" } +# Search given executable in PATH (remove dependency for `which` command) +which() { + # Alias to Bash built-in command `type -P` + type -P "$@" +} + numeric() { # Condense the exploded argument into a single return value. # shellcheck disable=SC2086,SC2183 diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 581d65e56b..7cd025c555 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -1,27 +1,5 @@ export HOMEBREW_REQUIRED_RUBY_VERSION=2.6.3 -# Search given executable in all PATH entries (remove dependency for `which` command) -which_all() { - if [[ $# -ne 1 ]] - then - return 1 - fi - - local executable entries entry retcode=1 - IFS=':' read -r -a entries <<< "${PATH}" # `readarray -d ':' -t` seems not applicable on WSL Bash - for entry in "${entries[@]}" - do - executable="${entry}/$1" - if [[ -x "${executable}" ]] - then - echo "${executable}" - retcode=0 # present - fi - done - - return "${retcode}" -} - # HOMEBREW_LIBRARY is from the user environment # shellcheck disable=SC2154 test_ruby() { @@ -46,13 +24,18 @@ find_ruby() { local ruby_exec while read -r ruby_exec do - if test_ruby "${ruby_exec}"; then + if test_ruby "${ruby_exec}" + then echo "${ruby_exec}" break fi done < <( - which_all ruby - PATH="${HOMEBREW_PATH}" which_all ruby + # function which() is set by brew.sh + # it's aliased to `type -P` + # shellcheck disable=SC2230 + which -a ruby + # shellcheck disable=SC2230 + PATH="${HOMEBREW_PATH}" which -a ruby ) fi } From fc056cec59fb752840fe2a7da224d05b70b09860 Mon Sep 17 00:00:00 2001 From: XuehaiPan Date: Wed, 15 Sep 2021 02:04:50 +0800 Subject: [PATCH 2/3] docs: update documentation for shell requirement --- docs/Installation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/Installation.md b/docs/Installation.md index 956e672f7b..de7cefd2e7 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -16,7 +16,7 @@ it does it too. You have to confirm everything it will do before it starts. * Command Line Tools (CLT) for Xcode: `xcode-select --install`, [developer.apple.com/downloads](https://developer.apple.com/downloads) or [Xcode](https://itunes.apple.com/us/app/xcode/id497799835) [3](#3) -* A Bourne-compatible shell for installation (e.g. `bash` or `zsh`) [4](#4) +* The Bourne-again shell for installation (i.e. `bash`) [4](#4) ## Git Remote Mirroring @@ -75,5 +75,5 @@ Apple Developer account on older versions of Mac OS X. Sign up for free [here](https://developer.apple.com/register/index.action). 4 The one-liner installation method found on -[brew.sh](https://brew.sh) requires a Bourne-compatible shell (e.g. bash or -zsh). Notably, fish, tcsh and csh will not work. +[brew.sh](https://brew.sh) requires the Bourne-again shell, i.e. bash. +Notably, zsh, fish, tcsh and csh will not work. From 954c3596b27290913f502877ba12ea9f12132073 Mon Sep 17 00:00:00 2001 From: XuehaiPan Date: Wed, 15 Sep 2021 17:10:05 +0800 Subject: [PATCH 3/3] brew: fail fast when not using bash --- bin/brew | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/brew b/bin/brew index 78eaa033b7..3d75d3654a 100755 --- a/bin/brew +++ b/bin/brew @@ -7,6 +7,12 @@ if ! [[ -d "${PWD}" ]]; then exit 1 fi +# Fail fast with concise message when not using bash +if [ -z "${BASH_VERSION:-}" ]; then + echo "Error: Bash is required to run brew." >&2 + exit 1 +fi + quiet_cd() { cd "$@" &>/dev/null || return }