shell: Use .profile unless .bash_profile exists

This commit is contained in:
Shaun Jackman 2020-05-11 21:26:45 -07:00
parent 390778f2a5
commit 133ee7966d
9 changed files with 24 additions and 17 deletions

View File

@ -3,7 +3,7 @@
#: 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.
#: Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.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 $(brew shellenv)`
homebrew-shellenv() {
case "$SHELL" in

View File

@ -243,7 +243,8 @@ Environment variables specific to Homebrew Cask:
* `HOMEBREW_CASK_OPTS`:
This variable may contain any arguments normally used as options on
the command-line. This is particularly useful to make options persistent.
For example, you might add to your .bash_profile or .zshenv something like:
For example, you might add to your ~/.profile, ~/.bash_profile, or ~/.zshenv
something like:
export HOMEBREW_CASK_OPTS='--appdir=~/Applications --fontdir=/Library/Fonts'

View File

@ -4,19 +4,19 @@ require "utils/shell"
describe Utils::Shell do
describe "::profile" do
it "returns ~/.bash_profile by default" do
it "returns ~/.profile by default" do
ENV["SHELL"] = "/bin/another_shell"
expect(subject.profile).to eq("~/.bash_profile")
expect(subject.profile).to eq("~/.profile")
end
it "returns ~/.bash_profile for sh" do
it "returns ~/.profile for sh" do
ENV["SHELL"] = "/bin/sh"
expect(subject.profile).to eq("~/.bash_profile")
expect(subject.profile).to eq("~/.profile")
end
it "returns ~/.bash_profile for Bash" do
it "returns ~/.profile for Bash" do
ENV["SHELL"] = "/bin/bash"
expect(subject.profile).to eq("~/.bash_profile")
expect(subject.profile).to eq("~/.profile")
end
it "returns /tmp/.zshrc for Zsh if ZDOTDIR is /tmp" do

View File

@ -39,9 +39,15 @@ module Utils
# return the shell profile file based on user's preferred shell
def profile
return "#{ENV["ZDOTDIR"]}/.zshrc" if preferred == :zsh && ENV["ZDOTDIR"].present?
case preferred
when :bash
bash_profile = "#{ENV["HOME"]}/.bash_profile"
return bash_profile if File.exist? bash_profile
when :zsh
return "#{ENV["ZDOTDIR"]}/.zshrc" if ENV["ZDOTDIR"].present?
end
SHELL_PROFILE_MAP.fetch(preferred, "~/.bash_profile")
SHELL_PROFILE_MAP.fetch(preferred, "~/.profile")
end
def set_variable_in_profile(variable, value)
@ -67,12 +73,12 @@ module Utils
end
SHELL_PROFILE_MAP = {
bash: "~/.bash_profile",
bash: "~/.profile",
csh: "~/.cshrc",
fish: "~/.config/fish/config.fish",
ksh: "~/.kshrc",
mksh: "~/.kshrc",
sh: "~/.bash_profile",
sh: "~/.profile",
tcsh: "~/.tcshrc",
zsh: "~/.zshrc",
}.freeze

View File

@ -114,7 +114,7 @@ sudo cpan local::lib
Note that this will install some other dependencies like `Module::Install`.
Then put the appropriate incantation in your shells startup, e.g. for
`.bash_profile` you insert the below, for others see the
`.profile` you insert the below, for others see the
[`local::lib`](https://metacpan.org/pod/local::lib) docs.
```sh

View File

@ -435,7 +435,7 @@ ones). No online search is performed.
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.
Consider adding evaluation of this command's output to your dotfiles (e.g. `~/.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 $(brew shellenv)`
### `switch` *`formula`* *`version`*

View File

@ -8,7 +8,7 @@ You must configure your shell to enable its completion support. This is because
## Configuring Completions in `bash`
To make Homebrew's completions available in `bash`, you must source the definitions as part of your shell's startup. Add the following to your `~/.bash_profile` file:
To make Homebrew's completions available in `bash`, you must source the definitions as part of your shell's startup. Add the following to your `~/.profile` file:
```sh
if type brew &>/dev/null; then

View File

@ -274,7 +274,7 @@ Environment variables specific to Homebrew Cask:
.
.TP
\fBHOMEBREW_CASK_OPTS\fR
This variable may contain any arguments normally used as options on the command\-line\. This is particularly useful to make options persistent\. For example, you might add to your \.bash_profile or \.zshenv something like:
This variable may contain any arguments normally used as options on the command\-line\. This is particularly useful to make options persistent\. For example, you might add to your ~/\.profile, ~/\.bash_profile, or ~/\.zshenv something like:
.
.IP "" 4
.

View File

@ -576,7 +576,7 @@ Search for \fItext\fR in the given package manager\'s list\.
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
The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. Consider adding evaluation of this command\'s output to your dotfiles (e\.g\. \fB~/\.bash_profile\fR or \fB~/\.zprofile\fR) with: \fBeval $(brew shellenv)\fR
The variables \fBHOMEBREW_PREFIX\fR, \fBHOMEBREW_CELLAR\fR and \fBHOMEBREW_REPOSITORY\fR are also exported to avoid querying them multiple times\. 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
.
.SS "\fBswitch\fR \fIformula\fR \fIversion\fR"
Symlink all of the specified \fIversion\fR of \fIformula\fR\'s installation into Homebrew\'s prefix\.