diff --git a/Library/Homebrew/test/utils/shell_spec.rb b/Library/Homebrew/test/utils/shell_spec.rb index b3a0ae8f7dc8a..c0d4e33e6f837 100644 --- a/Library/Homebrew/test/utils/shell_spec.rb +++ b/Library/Homebrew/test/utils/shell_spec.rb @@ -19,8 +19,15 @@ expect(subject.profile).to eq("~/.bash_profile") end + it "returns /tmp/.zshrc for Zsh if ZDOTDIR is /tmp" do + ENV["SHELL"] = "/bin/zsh" + ENV["ZDOTDIR"] = "/tmp" + expect(subject.profile).to eq("/tmp/.zshrc") + end + it "returns ~/.zshrc for Zsh" do ENV["SHELL"] = "/bin/zsh" + ENV["ZDOTDIR"] = nil expect(subject.profile).to eq("~/.zshrc") end diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 31a807e84a412..a6f233a259122 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -39,6 +39,8 @@ def export_value(key, value, shell = preferred) # return the shell profile file based on user's preferred shell def profile + return "#{ENV["ZDOTDIR"]}/.zshrc" if preferred == :zsh && ENV["ZDOTDIR"].present? + SHELL_PROFILE_MAP.fetch(preferred, "~/.bash_profile") end