Merge pull request #14798 from MikeMcQuaid/deprecate_shell

Deprecate `preferred_shell` and `shell_profile`.
This commit is contained in:
Mike McQuaid 2023-02-28 15:18:00 +00:00 committed by GitHub
commit 7c15dce285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View File

@ -43,6 +43,8 @@ module Homebrew
ENV["VERBOSE"] = "1" if args.verbose?
preferred_shell = Utils::Shell.preferred_path(default: "/bin/bash")
if args.cmd.present?
safe_system(preferred_shell, "-c", args.cmd)
elsif args.named.present?

View File

@ -220,7 +220,7 @@ module Kernel
FileUtils.touch "#{home}/.zshrc"
end
Process.wait fork { exec preferred_shell }
Process.wait fork { exec Utils::Shell.preferred_path(default: "/bin/bash") }
return if $CHILD_STATUS.success?
raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited?
@ -530,11 +530,13 @@ module Kernel
sig { returns(String) }
def preferred_shell
ENV.fetch("SHELL", "/bin/sh")
odeprecated "preferred_shell"
Utils::Shell.preferred_path(default: "/bin/sh")
end
sig { returns(String) }
def shell_profile
odeprecated "shell_profile"
Utils::Shell.profile
end

View File

@ -85,13 +85,13 @@ describe Utils::Shell do
it "supports tcsh" do
ENV["SHELL"] = "/bin/tcsh"
expect(described_class.prepend_path_in_profile(path))
.to eq("echo 'setenv PATH #{path}:$PATH' >> #{shell_profile}")
.to eq("echo 'setenv PATH #{path}:$PATH' >> #{described_class.profile}")
end
it "supports Bash" do
ENV["SHELL"] = "/bin/bash"
expect(described_class.prepend_path_in_profile(path))
.to eq("echo 'export PATH=\"#{path}:$PATH\"' >> #{shell_profile}")
.to eq("echo 'export PATH=\"#{path}:$PATH\"' >> #{described_class.profile}")
end
it "supports fish" do

View File

@ -18,9 +18,14 @@ module Utils
shell_name.to_sym if %w[bash csh fish ksh mksh sh tcsh zsh].include?(shell_name)
end
sig { params(default: String).returns(String) }
def preferred_path(default: "")
ENV.fetch("SHELL", default)
end
sig { returns(T.nilable(Symbol)) }
def preferred
from_path(ENV.fetch("SHELL", ""))
from_path(preferred_path)
end
sig { returns(T.nilable(Symbol)) }