brew/Library/Homebrew/cmd/shellenv.rb
Mike McQuaid bbf5a9f479
env_config: use environment variables consistently
- 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 https://github.com/Homebrew/homebrew-bundle/pull/1579 making
similar changes for Homebrew/homebrew-bundle.
2025-01-27 14:21:27 +00:00

33 lines
1.2 KiB
Ruby

# typed: strict
# frozen_string_literal: true
require "abstract_command"
require "shell_command"
module Homebrew
module Cmd
class Shellenv < AbstractCommand
include ShellCommand
cmd_args do
description <<~EOS
Valid shells: bash|csh|fish|pwsh|sh|tcsh|zsh
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. `${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.
EOS
named_args :shell
end
end
end
end