From 960b8b659c0d3c35df650aa3e2a25a89c81c87fb Mon Sep 17 00:00:00 2001 From: David O'Trakoun Date: Sun, 6 Oct 2019 12:03:01 -0400 Subject: [PATCH 1/3] Support for zsh ZDOTDIR, FIX #6533 - Add test spec with ZDOTDIR set and unset --- Library/Homebrew/test/utils/shell_spec.rb | 7 +++++++ Library/Homebrew/utils/shell.rb | 1 + 2 files changed, 8 insertions(+) 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..9bd8b35399bd3 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -39,6 +39,7 @@ def export_value(key, value, shell = preferred) # return the shell profile file based on user's preferred shell def profile + return ENV.fetch("ZDOTDIR", "~") + "/.zshrc" if preferred.eql? "zsh" SHELL_PROFILE_MAP.fetch(preferred, "~/.bash_profile") end From 5ca4b433837b31c918514ccd8cc612807badfa20 Mon Sep 17 00:00:00 2001 From: David O'Trakoun Date: Mon, 7 Oct 2019 10:25:41 -0400 Subject: [PATCH 2/3] Update Library/Homebrew/utils/shell.rb Co-Authored-By: Mike McQuaid --- Library/Homebrew/utils/shell.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 9bd8b35399bd3..8066702bf5ab1 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -39,7 +39,8 @@ def export_value(key, value, shell = preferred) # return the shell profile file based on user's preferred shell def profile - return ENV.fetch("ZDOTDIR", "~") + "/.zshrc" if preferred.eql? "zsh" + return "#{ENV["ZDOTDIR"]}/.zshrc" if preferred == "zsh" && ENV["ZDOTDIR"].present? + SHELL_PROFILE_MAP.fetch(preferred, "~/.bash_profile") end From 36bc11b01a1f4bd8d8364842e7d477c6f285cddb Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 8 Oct 2019 12:10:31 +0100 Subject: [PATCH 3/3] utils/shell: match preferred shell by symbol. --- Library/Homebrew/utils/shell.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 8066702bf5ab1..a6f233a259122 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -39,8 +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? - + return "#{ENV["ZDOTDIR"]}/.zshrc" if preferred == :zsh && ENV["ZDOTDIR"].present? + SHELL_PROFILE_MAP.fetch(preferred, "~/.bash_profile") end