diff --git a/Library/Homebrew/dev-cmd/sh.rb b/Library/Homebrew/dev-cmd/sh.rb index f9285459f9..d1eaf4c812 100644 --- a/Library/Homebrew/dev-cmd/sh.rb +++ b/Library/Homebrew/dev-cmd/sh.rb @@ -44,16 +44,18 @@ module Homebrew ENV["VERBOSE"] = "1" if args.verbose? if args.cmd.present? - safe_system(ENV["SHELL"], "-c", args.cmd) + safe_system(preferred_shell, "-c", args.cmd) elsif args.named.present? - safe_system(ENV["SHELL"], args.named.first) + safe_system(preferred_shell, args.named.first) else - subshell = if ENV["SHELL"].include?("zsh") - "PS1='brew %B%F{green}%~%f%b$ ' #{ENV["SHELL"]} -d -f" - elsif ENV["SHELL"].include?("bash") - "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]} --noprofile --norc" + shell_type = Utils::Shell.preferred + subshell = case shell_type + when :zsh + "PS1='brew %B%F{green}%~%f%b$ ' #{preferred_shell} -d -f" + when :bash + "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell} --noprofile --norc" else - "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]}" + "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell}" end puts <<~EOS Your shell has been configured to use Homebrew's build environment; diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 126a11544c..dfe5ceb7f2 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -291,12 +291,12 @@ module Kernel ENV["HOMEBREW_DEBUG_INSTALL"] = f.full_name end - if ENV["SHELL"].include?("zsh") && (home = Dir.home).start_with?(HOMEBREW_TEMP.resolved_path.to_s) + if Utils::Shell.preferred == :zsh && (home = Dir.home).start_with?(HOMEBREW_TEMP.resolved_path.to_s) FileUtils.mkdir_p home FileUtils.touch "#{home}/.zshrc" end - Process.wait fork { exec ENV.fetch("SHELL") } + Process.wait fork { exec preferred_shell } return if $CHILD_STATUS.success? raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited? @@ -608,6 +608,11 @@ module Kernel end end + sig { returns(String) } + def preferred_shell + ENV.fetch("SHELL", "/bin/sh") + end + sig { returns(String) } def shell_profile Utils::Shell.profile