From 453990f1aa7435c79b5a2af4acf043b93149bf19 Mon Sep 17 00:00:00 2001 From: Xu Cheng Date: Tue, 24 Mar 2015 21:03:20 +0800 Subject: [PATCH] add method to detect shell profile file based on users' preference shell Closes Homebrew/homebrew#38017. Signed-off-by: Xu Cheng --- Library/Homebrew/cmd/doctor.rb | 6 +++--- Library/Homebrew/formula_cellar_checks.rb | 2 +- Library/Homebrew/utils.rb | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index e110470746..4d253e639a 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -570,7 +570,7 @@ def check_user_path_1 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"' >> ~/.bash_profile + echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} EOS end end @@ -588,7 +588,7 @@ def check_user_path_2 <<-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"' >> ~/.bash_profile + echo 'export PATH="#{HOMEBREW_PREFIX}/bin:$PATH"' >> #{shell_profile} EOS end end @@ -602,7 +602,7 @@ def check_user_path_3 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"' >> ~/.bash_profile + echo 'export PATH="#{HOMEBREW_PREFIX}/sbin:$PATH"' >> #{shell_profile} EOS end end diff --git a/Library/Homebrew/formula_cellar_checks.rb b/Library/Homebrew/formula_cellar_checks.rb index 98d1073eae..89f3a45f5d 100644 --- a/Library/Homebrew/formula_cellar_checks.rb +++ b/Library/Homebrew/formula_cellar_checks.rb @@ -12,7 +12,7 @@ module FormulaCellarChecks <<-EOS.undent #{prefix_bin} is not in your PATH - You can amend this by altering your ~/.bashrc file + You can amend this by altering your #{shell_profile} file EOS end diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 4b2feb053f..2cdd920c93 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -291,6 +291,16 @@ 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 + module GitHub extend self ISSUES_URI = URI.parse("https://api.github.com/search/issues")