style: fix inconsistent code style for shell scripts

This commit is contained in:
XuehaiPan 2021-09-16 01:04:06 +08:00
parent c2d5d84b21
commit bd8db0737d
4 changed files with 20 additions and 11 deletions

View File

@ -74,7 +74,8 @@ esac
# These variables are set from the user environment.
# shellcheck disable=SC2154
ohai() {
if [[ -n "${HOMEBREW_COLOR}" || (-t 1 && -z "${HOMEBREW_NO_COLOR}") ]] # check whether stdout is a tty.
# Check whether stdout is a tty.
if [[ -n "${HOMEBREW_COLOR}" || (-t 1 && -z "${HOMEBREW_NO_COLOR}") ]]
then
echo -e "\\033[34m==>\\033[0m \\033[1m$*\\033[0m" # blue arrow and bold text
else
@ -83,7 +84,8 @@ ohai() {
}
opoo() {
if [[ -n "${HOMEBREW_COLOR}" || (-t 2 && -z "${HOMEBREW_NO_COLOR}") ]] # check whether stderr is a tty.
# Check whether stderr is a tty.
if [[ -n "${HOMEBREW_COLOR}" || (-t 2 && -z "${HOMEBREW_NO_COLOR}") ]]
then
echo -ne "\\033[4;33mWarning\\033[0m: " >&2 # highlight Warning with underline and yellow color
else
@ -98,7 +100,8 @@ opoo() {
}
bold() {
if [[ -n "${HOMEBREW_COLOR}" || (-t 2 && -z "${HOMEBREW_NO_COLOR}") ]] # check whether stderr is a tty.
# Check whether stderr is a tty.
if [[ -n "${HOMEBREW_COLOR}" || (-t 2 && -z "${HOMEBREW_NO_COLOR}") ]]
then
echo -e "\\033[1m""$*""\\033[0m"
else
@ -107,7 +110,8 @@ bold() {
}
onoe() {
if [[ -n "${HOMEBREW_COLOR}" || (-t 2 && -z "${HOMEBREW_NO_COLOR}") ]] # check whether stderr is a tty.
# Check whether stderr is a tty.
if [[ -n "${HOMEBREW_COLOR}" || (-t 2 && -z "${HOMEBREW_NO_COLOR}") ]]
then
echo -ne "\\033[4;31mError\\033[0m: " >&2 # highlight Error with underline and red color
else

View File

@ -10,8 +10,11 @@
# HOMEBREW_REPOSITORY is set by bin/brew
# shellcheck disable=SC2154
homebrew-shellenv() {
[[ "${HOMEBREW_SHELLENV_PREFIX}" == "${HOMEBREW_PREFIX}" ]] &&
[[ "$(PATH="${HOMEBREW_PATH}" command -v brew)" == "${HOMEBREW_PREFIX}/bin/brew" ]] && return
if [[ "${HOMEBREW_SHELLENV_PREFIX}" == "${HOMEBREW_PREFIX}" ]] &&
[[ "$(PATH="${HOMEBREW_PATH}" command -v brew)" == "${HOMEBREW_PREFIX}/bin/brew" ]]
then
return
fi
case "$(/bin/ps -p "${PPID}" -c -o comm=)" in
fish | -fish)

View File

@ -650,7 +650,7 @@ EOS
# shellcheck disable=SC2031
if [[ -n "${HOMEBREW_INSTALL_FROM_API}" ]] &&
[[ -n "${HOMEBREW_UPDATE_PREINSTALL}" ]] &&
[[ "${DIR}" == "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" || \
[[ "${DIR}" == "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core" ||
"${DIR}" == "${HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-cask" ]]
then
continue

View File

@ -2,13 +2,15 @@
set +o posix
# Fail fast with concise message when cwd does not exist
if ! [[ -d "${PWD}" ]]; then
if ! [[ -d "${PWD}" ]]
then
echo "Error: The current working directory doesn't exist, cannot proceed." >&2
exit 1
fi
# Fail fast with concise message when not using bash
if [ -z "${BASH_VERSION:-}" ]; then
if [ -z "${BASH_VERSION:-}" ]
then
echo "Error: Bash is required to run brew." >&2
exit 1
fi