From 9a29a306cfd6b116a0cb696ce56bd7bc7679a8e3 Mon Sep 17 00:00:00 2001 From: Greg Nisbet Date: Wed, 10 Aug 2016 23:19:09 -0700 Subject: [PATCH 1/5] resolve conflict in diagnostic.rb --- Library/Homebrew/cmd/--env.rb | 22 +++++- Library/Homebrew/diagnostic.rb | 7 +- Library/Homebrew/extend/os/mac/diagnostic.rb | 2 +- .../Homebrew/test/test_integration_cmds.rb | 20 +++++ Library/Homebrew/test/test_shell.rb | 38 ++++++++++ Library/Homebrew/test/test_utils.rb | 11 +-- Library/Homebrew/utils/shell.rb | 73 +++++++++++++++++++ 7 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 Library/Homebrew/test/test_shell.rb create mode 100644 Library/Homebrew/utils/shell.rb diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index 281175c934..292bcf866d 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -3,6 +3,7 @@ require "extend/ENV" require "build_environment" +require "utils/shell" module Homebrew def __env @@ -11,12 +12,25 @@ module Homebrew ENV.setup_build_environment ENV.universal_binary if ARGV.build_universal? - if $stdout.tty? + shell_value = ARGV.value("shell") + has_plain = ARGV.include?("--plain") + + if has_plain + shell = nil + elsif shell_value.nil? + # legacy behavior + shell = :bash unless $stdout.tty? + elsif shell_value == "auto" + shell = Utils::Shell.parent_shell || Utils::Shell.preferred_shell + elsif shell_value + shell = Utils::Shell.path_to_shell(shell_value) + end + + env_keys = build_env_keys(ENV) + if shell.nil? dump_build_env ENV else - build_env_keys(ENV).each do |key| - puts "export #{key}=\"#{ENV[key]}\"" - end + env_keys.each { |key| puts Utils::Shell.export_value(shell, key, ENV[key]) } end end end diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 5d83c4b5a3..b2f92c5f44 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -3,6 +3,7 @@ require "language/python" require "formula" require "version" require "development_tools" +require "utils/shell" module Homebrew module Diagnostic @@ -475,7 +476,7 @@ module Homebrew Consider setting your PATH so that #{HOMEBREW_PREFIX}/bin occurs before /usr/bin. Here is a one-liner: - echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} + echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{Utils::Shell.shell_profile} EOS end end @@ -495,7 +496,7 @@ module Homebrew <<-EOS.undent Homebrew's bin was not found in your PATH. Consider setting the PATH for example like so - echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} + echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{Utils::Shell.shell_profile} EOS end @@ -510,7 +511,7 @@ module Homebrew Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in #{HOMEBREW_PREFIX}/sbin. Consider setting the PATH for example like so - echo 'export PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"' >> #{shell_profile} + echo 'export PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"' >> #{Utils::Shell.shell_profile} EOS end diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 120e5d15cf..9b018bd020 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -202,7 +202,7 @@ module Homebrew SSL_CERT_DIR support was removed from Apple's curl. If fetching formulae fails you should: unset SSL_CERT_DIR - and remove it from #{shell_profile} if present. + and remove it from #{Utils::Shell.shell_profile} if present. EOS end diff --git a/Library/Homebrew/test/test_integration_cmds.rb b/Library/Homebrew/test/test_integration_cmds.rb index 330e7c0a85..4c03303406 100644 --- a/Library/Homebrew/test/test_integration_cmds.rb +++ b/Library/Homebrew/test/test_integration_cmds.rb @@ -227,6 +227,26 @@ class IntegrationCommandTests < Homebrew::TestCase cmd("--env")) end + def test_env_bash + assert_match %r{export CMAKE_PREFIX_PATH="#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"}, + cmd("--env", "--shell=bash") + end + + def test_env_fish + assert_match %r{set [-]gx CMAKE_PREFIX_PATH "#{Regexp.quote(HOMEBREW_PREFIX.to_s)}"}, + cmd("--env", "--shell=fish") + end + + def test_env_csh + assert_match %r{setenv CMAKE_PREFIX_PATH}, + cmd("--env", "--shell=tcsh") + end + + def test_env_plain + assert_match %r{CMAKE_PREFIX_PATH: #{Regexp.quote(HOMEBREW_PREFIX)}}, + cmd("--env", "--plain") + end + def test_prefix_formula assert_match "#{HOMEBREW_CELLAR}/testball", cmd("--prefix", testball) diff --git a/Library/Homebrew/test/test_shell.rb b/Library/Homebrew/test/test_shell.rb new file mode 100644 index 0000000000..63ca5adaa3 --- /dev/null +++ b/Library/Homebrew/test/test_shell.rb @@ -0,0 +1,38 @@ +require "testing_env" +require "utils/shell" + +class ShellSmokeTest < Homebrew::TestCase + def test_path_to_shell() + # raw command name + assert_equal :bash, Utils::Shell.path_to_shell("bash") + # full path + assert_equal :bash, Utils::Shell.path_to_shell("/bin/bash") + # versions + assert_equal :zsh, Utils::Shell.path_to_shell("zsh-5.2") + # strip newline too + assert_equal :zsh, Utils::Shell.path_to_shell("zsh-5.2\n") + end + + def test_path_to_shell_failure() + assert_equal nil, Utils::Shell.path_to_shell("") + assert_equal nil, Utils::Shell.path_to_shell("@@@@@@") + assert_equal nil, Utils::Shell.path_to_shell("invalid_shell-4.2") + end + + def test_sh_quote() + assert_equal "''", Utils::Shell.sh_quote("") + assert_equal "\\\\", Utils::Shell.sh_quote("\\") + assert_equal "'\n'", Utils::Shell.sh_quote("\n") + assert_equal "\\$", Utils::Shell.sh_quote("$") + assert_equal "word", Utils::Shell.sh_quote("word") + end + + def test_csh_quote() + assert_equal "''", Utils::Shell.csh_quote("") + assert_equal "\\\\", Utils::Shell.csh_quote("\\") + # note this test is different + assert_equal "'\\\n'", Utils::Shell.csh_quote("\n") + assert_equal "\\$", Utils::Shell.csh_quote("$") + assert_equal "word", Utils::Shell.csh_quote("word") + end +end diff --git a/Library/Homebrew/test/test_utils.rb b/Library/Homebrew/test/test_utils.rb index 9b55965b54..3d30baf9c1 100644 --- a/Library/Homebrew/test/test_utils.rb +++ b/Library/Homebrew/test/test_utils.rb @@ -1,6 +1,7 @@ require "testing_env" require "utils" require "tempfile" +require "utils/shell" class TtyTests < Homebrew::TestCase def test_strip_ansi @@ -157,15 +158,15 @@ class UtilTests < Homebrew::TestCase def test_shell_profile ENV["SHELL"] = "/bin/sh" - assert_equal "~/.bash_profile", shell_profile + assert_equal "~/.bash_profile", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/bash" - assert_equal "~/.bash_profile", shell_profile + assert_equal "~/.bash_profile", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/another_shell" - assert_equal "~/.bash_profile", shell_profile + assert_equal "~/.bash_profile", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/zsh" - assert_equal "~/.zshrc", shell_profile + assert_equal "~/.zshrc", Utils::Shell.shell_profile ENV["SHELL"] = "/bin/ksh" - assert_equal "~/.kshrc", shell_profile + assert_equal "~/.kshrc", Utils::Shell.shell_profile end def test_popen_read diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb new file mode 100644 index 0000000000..ca6eace8b0 --- /dev/null +++ b/Library/Homebrew/utils/shell.rb @@ -0,0 +1,73 @@ +module Utils + SHELL_PROFILE_MAP = { + :bash => "~/.bash_profile", + :csh => "~/.cshrc", + :fish => "~/.config/fish/config.fish", + :ksh => "~/.kshrc", + :sh => "~/.bash_profile", + :tcsh => "~/.tcshrc", + :zsh => "~/.zshrc", + }.freeze + + module Shell + # take a path and heuristically convert it + # to a shell, return nil if there's no match + def self.path_to_shell(path) + # we only care about the basename + shell_name = File.basename(path) + # handle possible version suffix like `zsh-5.2` + shell_name.sub!(/-.*\z/m, "") + shell_name.to_sym if %w[bash csh fish ksh sh tcsh zsh].include?(shell_name) + end + + def self.preferred_shell + path_to_shell(ENV.fetch("SHELL", "")) + end + + def self.parent_shell + path_to_shell(`ps -p #{Process.ppid} -o ucomm=`.strip) + end + + def self.csh_quote(str) + # ruby's implementation of shell_escape + str = str.to_s + return "''" if str.empty? + str = str.dup + # anything that isn't a known safe character is padded + str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\" + "\\1") + str.gsub!(/\n/, "'\\\n'") + str + end + + def self.sh_quote(str) + # ruby's implementation of shell_escape + str = str.to_s + return "''" if str.empty? + str = str.dup + # anything that isn't a known safe character is padded + str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\" + "\\1") + str.gsub!(/\n/, "'\n'") + str + end + + # quote values. quoting keys is overkill + def self.export_value(shell, key, value) + case shell + when :bash, :ksh, :sh, :zsh + "export #{key}=\"#{sh_quote(value)}\"" + when :fish + # fish quoting is mostly Bourne compatible except that + # a single quote can be included in a single-quoted string via \' + # and a literal \ can be included via \\ + "set -gx #{key} \"#{sh_quote(value)}\"" + when :csh, :tcsh + "setenv #{key} #{csh_quote(value)}" + end + end + + # return the shell profile file based on users' preferred shell + def self.shell_profile + SHELL_PROFILE_MAP.fetch(preferred_shell, "~/.bash_profile") + end + end +end From f1ce3585511c6c13a0628534c0399a3638f98596 Mon Sep 17 00:00:00 2001 From: Greg Nisbet Date: Fri, 13 May 2016 00:23:14 -0700 Subject: [PATCH 2/5] Utils::Shell.shell_profile in formula_cellar_checks --- Library/Homebrew/formula_cellar_checks.rb | 4 +++- Library/Homebrew/test/test_integration_cmds.rb | 2 +- Library/Homebrew/test/test_shell.rb | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 0a798b27e9..f527c453bd 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -1,3 +1,5 @@ +require "utils/shell" + module FormulaCellarChecks def check_PATH(bin) # warn the user if stuff was installed outside of their PATH @@ -12,7 +14,7 @@ module FormulaCellarChecks <<-EOS.undent #{prefix_bin} is not in your PATH - You can amend this by altering your #{shell_profile} file + You can amend this by altering your #{Utils::Shell.shell_profile} file EOS end diff --git a/Library/Homebrew/test/test_integration_cmds.rb b/Library/Homebrew/test/test_integration_cmds.rb index 4c03303406..1a5db6b6f3 100644 --- a/Library/Homebrew/test/test_integration_cmds.rb +++ b/Library/Homebrew/test/test_integration_cmds.rb @@ -238,7 +238,7 @@ class IntegrationCommandTests < Homebrew::TestCase end def test_env_csh - assert_match %r{setenv CMAKE_PREFIX_PATH}, + assert_match %r{setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)}}, cmd("--env", "--shell=tcsh") end diff --git a/Library/Homebrew/test/test_shell.rb b/Library/Homebrew/test/test_shell.rb index 63ca5adaa3..5a10574579 100644 --- a/Library/Homebrew/test/test_shell.rb +++ b/Library/Homebrew/test/test_shell.rb @@ -30,7 +30,7 @@ class ShellSmokeTest < Homebrew::TestCase def test_csh_quote() assert_equal "''", Utils::Shell.csh_quote("") assert_equal "\\\\", Utils::Shell.csh_quote("\\") - # note this test is different + # note this test is different than for sh assert_equal "'\\\n'", Utils::Shell.csh_quote("\n") assert_equal "\\$", Utils::Shell.csh_quote("$") assert_equal "word", Utils::Shell.csh_quote("word") From f0cc815d86aceec61adca10606124ad840b0398a Mon Sep 17 00:00:00 2001 From: Greg Nisbet Date: Sun, 22 May 2016 16:03:51 -0700 Subject: [PATCH 3/5] Multi-shell diagnostic check --- Library/Homebrew/diagnostic.rb | 6 +++--- Library/Homebrew/utils/shell.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index b2f92c5f44..d032ecff5f 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -476,7 +476,7 @@ module Homebrew Consider setting your PATH so that #{HOMEBREW_PREFIX}/bin occurs before /usr/bin. Here is a one-liner: - echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{Utils::Shell.shell_profile} + #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/bin")} EOS end end @@ -496,7 +496,7 @@ module Homebrew <<-EOS.undent Homebrew's bin was not found in your PATH. Consider setting the PATH for example like so - echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{Utils::Shell.shell_profile} + #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/bin:$PATH")} EOS end @@ -511,7 +511,7 @@ module Homebrew Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in #{HOMEBREW_PREFIX}/sbin. Consider setting the PATH for example like so - echo 'export PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"' >> #{Utils::Shell.shell_profile} + #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/sbin:$PATH")} EOS end diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index ca6eace8b0..d2301345fa 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -69,5 +69,16 @@ module Utils def self.shell_profile SHELL_PROFILE_MAP.fetch(preferred_shell, "~/.bash_profile") end + + def self.prepend_path_in_shell_profile(path) + case preferred_shell + when :bash, :ksh, :sh, :zsh + "echo 'export PATH=\"#{sh_quote(path)}:$PATH >> #{shell_profile}" + when :csh, :tcsh + "echo 'setenv PATH #{csh_quote(path)}:$PATH' >> #{shell_profile}" + when :fish + "echo 'set -g fish_user_paths $fish_user_paths >> #{sh_quote(path)}' >> #{shell_profile}" + end + end end end From bf63c08d50acb5fa79413325029e67e2c28a6023 Mon Sep 17 00:00:00 2001 From: Greg Nisbet Date: Sun, 22 May 2016 18:02:39 -0700 Subject: [PATCH 4/5] tests for shell-specific diagnostic message --- Library/Homebrew/cmd/--env.rb | 3 +-- Library/Homebrew/diagnostic.rb | 4 ++-- .../Homebrew/test/test_integration_cmds.rb | 2 +- Library/Homebrew/test/test_shell.rb | 21 +++++++++++++++++++ Library/Homebrew/utils/shell.rb | 17 ++++++++------- 5 files changed, 35 insertions(+), 12 deletions(-) diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index 292bcf866d..0feb338dc8 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -13,9 +13,8 @@ module Homebrew ENV.universal_binary if ARGV.build_universal? shell_value = ARGV.value("shell") - has_plain = ARGV.include?("--plain") - if has_plain + if ARGV.include?("--plain") shell = nil elsif shell_value.nil? # legacy behavior diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index d032ecff5f..86593ff7b6 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -496,7 +496,7 @@ module Homebrew <<-EOS.undent Homebrew's bin was not found in your PATH. Consider setting the PATH for example like so - #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/bin:$PATH")} + #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/bin")} EOS end @@ -511,7 +511,7 @@ module Homebrew Homebrew's sbin was not found in your PATH but you have installed formulae that put executables in #{HOMEBREW_PREFIX}/sbin. Consider setting the PATH for example like so - #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/sbin:$PATH")} + #{Utils::Shell.prepend_path_in_shell_profile("#{HOMEBREW_PREFIX}/sbin")} EOS end diff --git a/Library/Homebrew/test/test_integration_cmds.rb b/Library/Homebrew/test/test_integration_cmds.rb index 1a5db6b6f3..8801071d22 100644 --- a/Library/Homebrew/test/test_integration_cmds.rb +++ b/Library/Homebrew/test/test_integration_cmds.rb @@ -238,7 +238,7 @@ class IntegrationCommandTests < Homebrew::TestCase end def test_env_csh - assert_match %r{setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)}}, + assert_match %r{setenv CMAKE_PREFIX_PATH #{Regexp.quote(HOMEBREW_PREFIX.to_s)};}, cmd("--env", "--shell=tcsh") end diff --git a/Library/Homebrew/test/test_shell.rb b/Library/Homebrew/test/test_shell.rb index 5a10574579..5e054f9d9f 100644 --- a/Library/Homebrew/test/test_shell.rb +++ b/Library/Homebrew/test/test_shell.rb @@ -35,4 +35,25 @@ class ShellSmokeTest < Homebrew::TestCase assert_equal "\\$", Utils::Shell.csh_quote("$") assert_equal "word", Utils::Shell.csh_quote("word") end + + def prepend_path_shell(shell, path, fragment) + original_shell = ENV["SHELL"] + ENV["SHELL"] = shell + + prepend_message = Utils::Shell.prepend_path_in_shell_profile(path) + assert( + prepend_message.start_with?(fragment), + "#{shell}: expected #{prepend_message} to match #{fragment}" + ) + + ENV["SHELL"] = original_shell + end + + def test_prepend_path_in_shell_profile() + prepend_path_shell "/bin/tcsh", "/path", "echo 'setenv PATH /path" + + prepend_path_shell "/bin/bash", "/path", "echo 'export PATH=\"/path" + + prepend_path_shell "/usr/local/bin/fish", "/path", "echo 'set -g fish_user_paths \"/path\" $fish_user_paths' >>" + end end diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index d2301345fa..19e696795f 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -10,8 +10,10 @@ module Utils }.freeze module Shell + UNSAFE_SHELL_CHAR = /([^A-Za-z0-9_\-.,:\/@\n])/ + # take a path and heuristically convert it - # to a shell, return nil if there's no match + # to a shell name, return nil if there's no match def self.path_to_shell(path) # we only care about the basename shell_name = File.basename(path) @@ -34,7 +36,8 @@ module Utils return "''" if str.empty? str = str.dup # anything that isn't a known safe character is padded - str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\" + "\\1") + str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") + # newlines have to be specially quoted in csh str.gsub!(/\n/, "'\\\n'") str end @@ -45,7 +48,7 @@ module Utils return "''" if str.empty? str = str.dup # anything that isn't a known safe character is padded - str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/, "\\\\" + "\\1") + str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") str.gsub!(/\n/, "'\n'") str end @@ -61,7 +64,7 @@ module Utils # and a literal \ can be included via \\ "set -gx #{key} \"#{sh_quote(value)}\"" when :csh, :tcsh - "setenv #{key} #{csh_quote(value)}" + "setenv #{key} #{csh_quote(value)};" end end @@ -72,12 +75,12 @@ module Utils def self.prepend_path_in_shell_profile(path) case preferred_shell - when :bash, :ksh, :sh, :zsh - "echo 'export PATH=\"#{sh_quote(path)}:$PATH >> #{shell_profile}" + when :bash, :ksh, :sh, :zsh, nil + "echo 'export PATH=\"#{sh_quote(path)}:$PATH'\" >> #{shell_profile}" when :csh, :tcsh "echo 'setenv PATH #{csh_quote(path)}:$PATH' >> #{shell_profile}" when :fish - "echo 'set -g fish_user_paths $fish_user_paths >> #{sh_quote(path)}' >> #{shell_profile}" + "echo 'set -g fish_user_paths \"#{sh_quote(path)}\" $fish_user_paths' >> #{shell_profile}" end end end From dcc3377aa30b34dfcced0df77696674f91a5a9f3 Mon Sep 17 00:00:00 2001 From: Greg Nisbet Date: Tue, 14 Jun 2016 22:31:48 -0700 Subject: [PATCH 5/5] move shell_profile to compat/utils.rb & deprecate --- Library/Homebrew/compat/utils.rb | 10 ++++++++++ Library/Homebrew/utils.rb | 10 ---------- Library/Homebrew/utils/shell.rb | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 Library/Homebrew/compat/utils.rb diff --git a/Library/Homebrew/compat/utils.rb b/Library/Homebrew/compat/utils.rb new file mode 100644 index 0000000000..7de5e85c32 --- /dev/null +++ b/Library/Homebrew/compat/utils.rb @@ -0,0 +1,10 @@ +# return the shell profile file based on users' preference shell +def shell_profile + opoo "shell_profile has been deprecated in favor of Utils::Shell.profile" + case ENV["SHELL"] + when %r{/(ba)?sh} then "~/.bash_profile" + when %r{/zsh} then "~/.zshrc" + when %r{/ksh} then "~/.kshrc" + else "~/.bash_profile" + end +end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index f78fbfcb7f..8e6a9b7d7e 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -519,16 +519,6 @@ def paths end.uniq.compact end -# return the shell profile file based on users' preference shell -def shell_profile - case ENV["SHELL"] - when %r{/(ba)?sh} then "~/.bash_profile" - when %r{/zsh} then "~/.zshrc" - when %r{/ksh} then "~/.kshrc" - else "~/.bash_profile" - end -end - def disk_usage_readable(size_in_bytes) if size_in_bytes >= 1_073_741_824 size = size_in_bytes.to_f / 1_073_741_824 diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index 19e696795f..c0d6b90ae6 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -76,7 +76,7 @@ module Utils def self.prepend_path_in_shell_profile(path) case preferred_shell when :bash, :ksh, :sh, :zsh, nil - "echo 'export PATH=\"#{sh_quote(path)}:$PATH'\" >> #{shell_profile}" + "echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{shell_profile}" when :csh, :tcsh "echo 'setenv PATH #{csh_quote(path)}:$PATH' >> #{shell_profile}" when :fish