Skip to content

Commit

Permalink
env_config: use environment variables consistently
Browse files Browse the repository at this point in the history
- use e.g. `$HOMEBREW_*` for cases where only the environment variable
  is the entire backtick-quoted string
- use e.g. `${HOMEBREW_*}` for cases where the environment variable is
  part of a backtick-quoted string to make clear what parts are variable
  and what parts are not
- use `export HOMEBREW_*=...` for cases where we're talking about
  setting the environment variable (because it likely needs to be
  exported to work how they want)

Inspired by Homebrew/homebrew-bundle#1579 making
similar changes for Homebrew/homebrew-bundle.
  • Loading branch information
MikeMcQuaid committed Jan 27, 2025
1 parent 9fd2b27 commit bbf5a9f
Show file tree
Hide file tree
Showing 24 changed files with 384 additions and 369 deletions.
26 changes: 13 additions & 13 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ class Config
{
appdir: "/Applications",
keyboard_layoutdir: "/Library/Keyboard Layouts",
colorpickerdir: "~/Library/ColorPickers",
prefpanedir: "~/Library/PreferencePanes",
qlplugindir: "~/Library/QuickLook",
mdimporterdir: "~/Library/Spotlight",
dictionarydir: "~/Library/Dictionaries",
fontdir: "~/Library/Fonts",
servicedir: "~/Library/Services",
input_methoddir: "~/Library/Input Methods",
internet_plugindir: "~/Library/Internet Plug-Ins",
audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components",
vst_plugindir: "~/Library/Audio/Plug-Ins/VST",
vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3",
screen_saverdir: "~/Library/Screen Savers",
colorpickerdir: "${HOME}/Library/ColorPickers",
prefpanedir: "${HOME}/Library/PreferencePanes",
qlplugindir: "${HOME}/Library/QuickLook",
mdimporterdir: "${HOME}/Library/Spotlight",
dictionarydir: "${HOME}/Library/Dictionaries",
fontdir: "${HOME}/Library/Fonts",
servicedir: "${HOME}/Library/Services",
input_methoddir: "${HOME}/Library/Input Methods",
internet_plugindir: "${HOME}/Library/Internet Plug-Ins",
audio_unit_plugindir: "${HOME}/Library/Audio/Plug-Ins/Components",
vst_plugindir: "${HOME}/Library/Audio/Plug-Ins/VST",
vst3_plugindir: "${HOME}/Library/Audio/Plug-Ins/VST3",
screen_saverdir: "${HOME}/Library/Screen Savers",
}.freeze,
T::Hash[Symbol, String],
)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/--cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.command_name = "--cache"

cmd_args do
description <<~EOS
Display Homebrew's download cache. See also `HOMEBREW_CACHE`.
Display Homebrew's download cache. See also `$HOMEBREW_CACHE`.
If a <formula> or <cask> is provided, display the file or directory used to cache it.
EOS
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CleanupCmd < AbstractCommand
Remove stale lock files and outdated downloads for all formulae and casks,
and remove old versions of installed formulae. If arguments are specified,
only do this for the given formulae and casks. Removes all downloads more than
#{days} days old. This can be adjusted with `HOMEBREW_CLEANUP_MAX_AGE_DAYS`.
#{days} days old. This can be adjusted with `$HOMEBREW_CLEANUP_MAX_AGE_DAYS`.
EOS
flag "--prune=",
description: "Remove all cache files older than specified <days>. " \
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Desc < AbstractCommand
"it is interpreted as a regular expression."
switch "--eval-all",
description: "Evaluate all available formulae and casks, whether installed or not, to search their " \
"descriptions. Implied if `HOMEBREW_EVAL_ALL` is set."
"descriptions. Implied if `$HOMEBREW_EVAL_ALL` is set."
switch "--formula", "--formulae",
description: "Treat all named arguments as formulae."
switch "--cask", "--casks",
Expand All @@ -48,7 +48,7 @@ def run

if search_type.present?
if !args.eval_all? && !Homebrew::EnvConfig.eval_all? && Homebrew::EnvConfig.no_install_from_api?
raise UsageError, "`brew desc --search` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
raise UsageError, "`brew desc --search` needs `--eval-all` passed or `$HOMEBREW_EVAL_ALL` set!"
end

query = args.named.join(" ")
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cmd/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Info < AbstractCommand
EOS
switch "--analytics",
description: "List global Homebrew analytics data or, if specified, installation and " \
"build error data for <formula> (provided neither `HOMEBREW_NO_ANALYTICS` " \
"nor `HOMEBREW_NO_GITHUB_API` are set)."
"build error data for <formula> (provided neither `$HOMEBREW_NO_ANALYTICS` " \
"nor `$HOMEBREW_NO_GITHUB_API` are set)."
flag "--days=",
depends_on: "--analytics",
description: "How many days of analytics data to retrieve. " \
Expand Down Expand Up @@ -57,7 +57,7 @@ class Info < AbstractCommand
switch "--eval-all",
depends_on: "--json",
description: "Evaluate all available formulae and casks, whether installed or not, to print their " \
"JSON. Implied if `HOMEBREW_EVAL_ALL` is set."
"JSON. Implied if `$HOMEBREW_EVAL_ALL` is set."
switch "--variations",
depends_on: "--json",
description: "Include the variations hash in each formula's JSON output."
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ class InstallCmd < AbstractCommand
Install a <formula> or <cask>. Additional options specific to a <formula> may be
appended to the command.
Unless `HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
Unless `$HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
outdated dependents and dependents with broken linkage, respectively.
Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for
Unless `$HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for
the installed formulae or, every 30 days, for all formulae.
Unless `HOMEBREW_NO_INSTALL_UPGRADE` is set, `brew install` <formula> will upgrade <formula> if it
Unless `$HOMEBREW_NO_INSTALL_UPGRADE` is set, `brew install` <formula> will upgrade <formula> if it
is already installed but outdated.
EOS
switch "-d", "--debug",
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/nodenv-sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Cmd
class NodenvSync < AbstractCommand
cmd_args do
description <<~EOS
Create symlinks for Homebrew's installed NodeJS versions in `~/.nodenv/versions`.
Create symlinks for Homebrew's installed NodeJS versions in `${HOME}/.nodenv/versions`.
Note that older version symlinks will also be created so e.g. NodeJS 19.1.0 will
also be symlinked to 19.0.0.
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/pyenv-sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Cmd
class PyenvSync < AbstractCommand
cmd_args do
description <<~EOS
Create symlinks for Homebrew's installed Python versions in `~/.pyenv/versions`.
Create symlinks for Homebrew's installed Python versions in `${HOME}/.pyenv/versions`.
Note that older patch version symlinks will be created and linked to the minor
version so e.g. Python 3.11.0 will also be symlinked to 3.11.3.
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/rbenv-sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Cmd
class RbenvSync < AbstractCommand
cmd_args do
description <<~EOS
Create symlinks for Homebrew's installed Ruby versions in `~/.rbenv/versions`.
Create symlinks for Homebrew's installed Ruby versions in `${HOME}/.rbenv/versions`.
Note that older version symlinks will also be created so e.g. Ruby 3.2.1 will
also be symlinked to 3.2.0.
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ReadallCmd < AbstractCommand
description: "Syntax-check all of Homebrew's Ruby files (if no <tap> is passed)."
switch "--eval-all",
description: "Evaluate all available formulae and casks, whether installed or not. " \
"Implied if `HOMEBREW_EVAL_ALL` is set."
"Implied if `$HOMEBREW_EVAL_ALL` is set."
switch "--no-simulate",
description: "Don't simulate other system configurations when checking formulae and casks."

Expand All @@ -50,7 +50,7 @@ def run

taps = if args.no_named?
if !args.eval_all? && !Homebrew::EnvConfig.eval_all?
raise UsageError, "`brew readall` needs a tap or `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
raise UsageError, "`brew readall` needs a tap or `--eval-all` passed or `$HOMEBREW_EVAL_ALL` set!"
end

Tap.installed
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/reinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class Reinstall < AbstractCommand
Uninstall and then reinstall a <formula> or <cask> using the same options it was
originally installed with, plus any appended options specific to a <formula>.
Unless `HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
Unless `$HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
outdated dependents and dependents with broken linkage, respectively.
Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
Unless `$HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
reinstalled formulae or, every 30 days, for all formulae.
EOS
switch "-d", "--debug",
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SearchCmd < AbstractCommand
switch "--eval-all",
depends_on: "--desc",
description: "Evaluate all available formulae and casks, whether installed or not, to search their " \
"descriptions. Implied if `HOMEBREW_EVAL_ALL` is set."
"descriptions. Implied if `$HOMEBREW_EVAL_ALL` is set."
switch "--pull-request",
description: "Search for GitHub pull requests containing <text>."
switch "--open",
Expand Down Expand Up @@ -71,7 +71,7 @@ def run

if args.desc?
if !args.eval_all? && !Homebrew::EnvConfig.eval_all? && Homebrew::EnvConfig.no_install_from_api?
raise UsageError, "`brew search --desc` needs `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
raise UsageError, "`brew search --desc` needs `--eval-all` passed or `$HOMEBREW_EVAL_ALL` set!"
end

Search.search_descriptions(string_or_regex, args)
Expand Down
13 changes: 8 additions & 5 deletions Library/Homebrew/cmd/shellenv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class Shellenv < AbstractCommand
Print export statements. When run in a shell, this installation of Homebrew will be added to your `PATH`, `MANPATH`, and `INFOPATH`.
The variables `HOMEBREW_PREFIX`, `HOMEBREW_CELLAR` and `HOMEBREW_REPOSITORY` are also exported to avoid querying them multiple times.
To help guarantee idempotence, this command produces no output when Homebrew's `bin` and `sbin` directories are first and second
respectively in your `PATH`. Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.bash_profile` or
`~/.zprofile` on macOS and `~/.bashrc` or `~/.zshrc` on Linux) with: `eval "$(brew shellenv)"`
The variables `$HOMEBREW_PREFIX`, `$HOMEBREW_CELLAR` and `$HOMEBREW_REPOSITORY` are also exported to avoid
querying them multiple times.
To help guarantee idempotence, this command produces no output when Homebrew's `bin` and `sbin` directories
are first and second respectively in your `PATH`. Consider adding evaluation of this command's output to
your dotfiles (e.g. `${HOME}/.bash_profile` or `${HOME}/.zprofile` on macOS and `${HOME}/.bashrc` or
`${HOME}/.zshrc` on Linux) with: `eval "$(brew shellenv)"`
The shell can be specified explicitly with a supported shell name parameter. Unknown shells will output POSIX exports.
The shell can be specified explicitly with a supported shell name parameter. Unknown shells will output
POSIX exports.
EOS
named_args :shell
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TapCmd < AbstractCommand
description: "Migrate tapped formulae from symlink-based to directory-based structure."
switch "--eval-all",
description: "Evaluate all the formulae, casks and aliases in the new tap to check validity. " \
"Implied if `HOMEBREW_EVAL_ALL` is set."
"Implied if `$HOMEBREW_EVAL_ALL` is set."
switch "-f", "--force",
description: "Force install core taps even under API mode."

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/upgrade.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class UpgradeCmd < AbstractCommand
installed with, plus any appended brew formula options. If <cask> or <formula> are specified,
upgrade only the given <cask> or <formula> kegs (unless they are pinned; see `pin`, `unpin`).
Unless `HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
Unless `$HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK` is set, `brew upgrade` or `brew reinstall` will be run for
outdated dependents and dependents with broken linkage, respectively.
Unless `HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
Unless `$HOMEBREW_NO_INSTALL_CLEANUP` is set, `brew cleanup` will then be run for the
upgraded formulae or, every 30 days, for all formulae.
EOS
switch "-d", "--debug",
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/uses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def intersection_of_dependents(use_runtime_dependents, used_formulae)
all = args.eval_all?

if !args.installed? && !(all || Homebrew::EnvConfig.eval_all?)
raise UsageError, "`brew uses` needs `--installed` or `--eval-all` passed or `HOMEBREW_EVAL_ALL` set!"
raise UsageError, "`brew uses` needs `--installed` or `--eval-all` passed or `$HOMEBREW_EVAL_ALL` set!"
end

if show_formulae_and_casks || args.formula?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LivecheckCmd < AbstractCommand
Check for newer versions of formulae and/or casks from upstream.
If no formula or cask argument is passed, the list of formulae and
casks to check is taken from `HOMEBREW_LIVECHECK_WATCHLIST` or
`~/.homebrew/livecheck_watchlist.txt`.
`${HOME}/.homebrew/livecheck_watchlist.txt`.
EOS
switch "--full-name",
description: "Print formulae and casks with fully-qualified names."
Expand Down
Loading

0 comments on commit bbf5a9f

Please sign in to comment.