Apply suggestions from code review

This commit is contained in:
XuehaiPan 2021-08-30 22:33:32 +08:00
parent 27fb6506a0
commit 05c1c5895e
4 changed files with 21 additions and 47 deletions

View File

@ -51,8 +51,23 @@ HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}"
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}" HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}" HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
# Don't need to handle a default case.
# HOMEBREW_LIBRARY set by bin/brew
# shellcheck disable=SC2249,SC2154
case "$*" in
--cellar) echo "${HOMEBREW_CELLAR}"; exit 0 ;;
--repository|--repo) echo "${HOMEBREW_REPOSITORY}"; exit 0 ;;
--caskroom) echo "${HOMEBREW_PREFIX}/Caskroom"; exit 0 ;;
--cache) echo "${HOMEBREW_CACHE}"; exit 0 ;;
shellenv) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/shellenv.sh"; homebrew-shellenv; exit 0 ;;
formulae) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/formulae.sh"; homebrew-formulae; exit 0 ;;
casks) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/casks.sh"; homebrew-casks; exit 0 ;;
# falls back to cmd/prefix.rb on a non-zero return
--prefix*) source "${HOMEBREW_LIBRARY}/Homebrew/prefix.sh"; homebrew-prefix "$@" && exit 0 ;;
esac
##### #####
##### Next, define helper functions for prompting. ##### Next, define all helper functions.
##### #####
# These variables are set from the user environment. # These variables are set from the user environment.
@ -110,25 +125,6 @@ odie() {
exit 1 exit 1
} }
# Don't need to handle a default case.
# HOMEBREW_LIBRARY set by bin/brew
# shellcheck disable=SC2249,SC2154
case "$*" in
--cellar) echo "${HOMEBREW_CELLAR}"; exit 0 ;;
--repository|--repo) echo "${HOMEBREW_REPOSITORY}"; exit 0 ;;
--caskroom) echo "${HOMEBREW_PREFIX}/Caskroom"; exit 0 ;;
--cache) echo "${HOMEBREW_CACHE}"; exit 0 ;;
shellenv) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/shellenv.sh"; homebrew-shellenv; exit 0 ;;
formulae) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/formulae.sh"; homebrew-formulae; exit 0 ;;
casks) source "${HOMEBREW_LIBRARY}/Homebrew/cmd/casks.sh"; homebrew-casks; exit 0 ;;
# falls back to cmd/prefix.rb on a non-zero return
--prefix*) source "${HOMEBREW_LIBRARY}/Homebrew/prefix.sh"; homebrew-prefix "$@" && exit 0 ;;
esac
#####
##### Next, define the reset of helper functions.
#####
safe_cd() { safe_cd() {
cd "$@" >/dev/null || odie "Failed to cd to $*!" cd "$@" >/dev/null || odie "Failed to cd to $*!"
} }

View File

@ -4,24 +4,14 @@
#: #:
#: The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times. #: The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times.
#: The variable `HOMEBREW_SHELLENV_PREFIX` will be exported to avoid adding duplicate entries to the environment variables. #: The variable `HOMEBREW_SHELLENV_PREFIX` will be exported to avoid adding duplicate entries to the environment variables.
#: #: Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)`
#: Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`)
#: with: `eval "$(/path/to/brew shellenv)"`.
#:
#: The variable `HOMEBREW_SHELLENV_PREFIX` may be inherited from the parent shell session. If you explicitly
#: modified the path variables (e.g. `PATH`) in your dotfiles which breaks the subshell varibale inheritecement,
#: please use `eval "$(HOMEBREW_SHELLENV_PREFIX='' /path/to/brew shellenv)"` to always get all the export statements.
# HOMEBREW_CELLAR and HOMEBREW_PREFIX are set by extend/ENV/super.rb # HOMEBREW_CELLAR and HOMEBREW_PREFIX are set by extend/ENV/super.rb
# HOMEBREW_REPOSITORY is set by bin/brew # HOMEBREW_REPOSITORY is set by bin/brew
# shellcheck disable=SC2154 # shellcheck disable=SC2154
homebrew-shellenv() { homebrew-shellenv() {
if [[ "${HOMEBREW_SHELLENV_PREFIX}" == "${HOMEBREW_PREFIX}" ]]; then [[ "${HOMEBREW_SHELLENV_PREFIX}" == "${HOMEBREW_PREFIX}" &&
[[ "$(PATH="${HOMEBREW_PATH}" command -v brew)" == "${HOMEBREW_PREFIX}/bin/brew" ]] && return "$(PATH="${HOMEBREW_PATH}" command -v brew)" == "${HOMEBREW_PREFIX}/bin/brew" ]] && return
opoo "You have set HOMEBREW_SHELLENV_PREFIX=\"${HOMEBREW_SHELLENV_PREFIX}\"," \
"but the brew's executable is not present in your PATH." \
"Please run \`brew help shellenv\` for more information."
fi
case "$(/bin/ps -p "${PPID}" -c -o comm=)" in case "$(/bin/ps -p "${PPID}" -c -o comm=)" in
fish | -fish) fish | -fish)

View File

@ -570,13 +570,7 @@ Print export statements. When run in a shell, this installation of Homebrew will
The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times. The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times.
The variable `HOMEBREW_SHELLENV_PREFIX` will be exported to avoid adding duplicate entries to the environment variables. The variable `HOMEBREW_SHELLENV_PREFIX` will be exported to avoid adding duplicate entries to the environment variables.
Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`) with: `eval $(brew shellenv)`
Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.profile`, `~/.bash_profile`, or `~/.zprofile`)
with: `eval "$(/path/to/brew shellenv)"`.
The variable `HOMEBREW_SHELLENV_PREFIX` may be inherited from the parent shell session. If you explicitly
modified the path variables (e.g. `PATH`) in your dotfiles which breaks the subshell varibale inheritecement,
please use `eval "$(HOMEBREW_SHELLENV_PREFIX='' /path/to/brew shellenv)"` to always get all the export statements.
### `tap` [*`options`*] [*`user`*`/`*`repo`*] [*`URL`*] ### `tap` [*`options`*] [*`user`*`/`*`repo`*] [*`URL`*]

View File

@ -792,13 +792,7 @@ Search for \fItext\fR in the given database\.
Print export statements\. When run in a shell, this installation of Homebrew will be added to your \fBPATH\fR, \fBMANPATH\fR, and \fBINFOPATH\fR\. Print export statements\. When run in a shell, this installation of Homebrew will be added to your \fBPATH\fR, \fBMANPATH\fR, and \fBINFOPATH\fR\.
. .
.P .P
The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. The variable \fBHOMEBREW_SHELLENV_PREFIX\fR will be exported to avoid adding duplicate entries to the environment variables\. The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. The variable \fBHOMEBREW_SHELLENV_PREFIX\fR will be exported to avoid adding duplicate entries to the environment variables\. Consider adding evaluation of this command\'s output to your dotfiles (e\.g\. \fB~/\.profile\fR, \fB~/\.bash_profile\fR, or \fB~/\.zprofile\fR) with: \fBeval $(brew shellenv)\fR
.
.P
Consider adding evaluation of this command\'s output to your dotfiles (e\.g\. \fB~/\.profile\fR, \fB~/\.bash_profile\fR, or \fB~/\.zprofile\fR) with: \fBeval "$(/path/to/brew shellenv)"\fR\.
.
.P
The variable \fBHOMEBREW_SHELLENV_PREFIX\fR may be inherited from the parent shell session\. If you explicitly modified the path variables (e\.g\. \fBPATH\fR) in your dotfiles which breaks the subshell varibale inheritecement, please use \fBeval "$(HOMEBREW_SHELLENV_PREFIX=\'\' /path/to/brew shellenv)"\fR to always get all the export statements\.
. .
.SS "\fBtap\fR [\fIoptions\fR] [\fIuser\fR\fB/\fR\fIrepo\fR] [\fIURL\fR]" .SS "\fBtap\fR [\fIoptions\fR] [\fIuser\fR\fB/\fR\fIrepo\fR] [\fIURL\fR]"
Tap a formula repository\. Tap a formula repository\.