Encapsulate ENV["SHELL"] usage

This commit is contained in:
Bo Anderson 2022-05-30 05:07:42 +01:00
parent e78665f4f7
commit 8ada737d40
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
2 changed files with 16 additions and 9 deletions

View File

@ -44,16 +44,18 @@ module Homebrew
ENV["VERBOSE"] = "1" if args.verbose? ENV["VERBOSE"] = "1" if args.verbose?
if args.cmd.present? if args.cmd.present?
safe_system(ENV["SHELL"], "-c", args.cmd) safe_system(preferred_shell, "-c", args.cmd)
elsif args.named.present? elsif args.named.present?
safe_system(ENV["SHELL"], args.named.first) safe_system(preferred_shell, args.named.first)
else else
subshell = if ENV["SHELL"].include?("zsh") shell_type = Utils::Shell.preferred
"PS1='brew %B%F{green}%~%f%b$ ' #{ENV["SHELL"]} -d -f" subshell = case shell_type
elsif ENV["SHELL"].include?("bash") when :zsh
"PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]} --noprofile --norc" "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 else
"PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]}" "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{preferred_shell}"
end end
puts <<~EOS puts <<~EOS
Your shell has been configured to use Homebrew's build environment; Your shell has been configured to use Homebrew's build environment;

View File

@ -291,12 +291,12 @@ module Kernel
ENV["HOMEBREW_DEBUG_INSTALL"] = f.full_name ENV["HOMEBREW_DEBUG_INSTALL"] = f.full_name
end 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.mkdir_p home
FileUtils.touch "#{home}/.zshrc" FileUtils.touch "#{home}/.zshrc"
end end
Process.wait fork { exec ENV.fetch("SHELL") } Process.wait fork { exec preferred_shell }
return if $CHILD_STATUS.success? return if $CHILD_STATUS.success?
raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited? raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited?
@ -608,6 +608,11 @@ module Kernel
end end
end end
sig { returns(String) }
def preferred_shell
ENV.fetch("SHELL", "/bin/sh")
end
sig { returns(String) } sig { returns(String) }
def shell_profile def shell_profile
Utils::Shell.profile Utils::Shell.profile