diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index dcf8e7a18a..1a7469e8c8 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -129,16 +129,16 @@ class Caveats Bash completion has been installed to: #{root_dir}/etc/bash_completion.d EOS - when :zsh - <<~EOS - zsh #{installed.join(" and ")} have been installed to: - #{root_dir}/share/zsh/site-functions - EOS when :fish fish_caveats = +"fish #{installed.join(" and ")} have been installed to:" fish_caveats << "\n #{root_dir}/share/fish/vendor_completions.d" if completion_installed fish_caveats << "\n #{root_dir}/share/fish/vendor_functions.d" if functions_installed fish_caveats.freeze + when :zsh + <<~EOS + zsh #{installed.join(" and ")} have been installed to: + #{root_dir}/share/zsh/site-functions + EOS end end diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 5a5453bac8..5b5d25e8fc 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -335,10 +335,10 @@ class Keg def completion_installed?(shell) dir = case shell when :bash then path/"etc/bash_completion.d" + when :fish then path/"share/fish/vendor_completions.d" when :zsh dir = path/"share/zsh/site-functions" dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") } - when :fish then path/"share/fish/vendor_completions.d" end dir&.directory? && !dir.children.empty? end diff --git a/Library/Homebrew/test/caveats_spec.rb b/Library/Homebrew/test/caveats_spec.rb index ad493a6c37..3a8ce307db 100644 --- a/Library/Homebrew/test/caveats_spec.rb +++ b/Library/Homebrew/test/caveats_spec.rb @@ -301,28 +301,34 @@ describe Caveats do let(:caveats) { described_class.new(f).caveats } let(:path) { f.prefix.resolved_path } + let(:bash_completion_dir) { path/"etc/bash_completion.d" } + let(:fish_vendor_completions) { path/"share/fish/vendor_completions.d" } + let(:zsh_site_functions) { path/"share/zsh/site-functions" } + before do # don't try to load/fetch gcc/glibc allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false) - allow_any_instance_of(Pathname).to receive(:children).and_return([Pathname.new("child")]) allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell")) allow(Utils::Shell).to receive_messages(preferred: nil, parent: nil) end - it "gives dir where Bash completions have been installed" do - (path/"etc/bash_completion.d").mkpath + it "includes where Bash completions have been installed to" do + bash_completion_dir.mkpath + FileUtils.touch bash_completion_dir/f.name expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d") end - it "gives dir where zsh completions have been installed" do - (path/"share/zsh/site-functions").mkpath - expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions") + it "includes where fish completions have been installed to" do + fish_vendor_completions.mkpath + FileUtils.touch fish_vendor_completions/f.name + expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") end - it "gives dir where fish completions have been installed" do - (path/"share/fish/vendor_completions.d").mkpath - expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d") + it "includes where zsh completions have been installed to" do + zsh_site_functions.mkpath + FileUtils.touch zsh_site_functions/f.name + expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions") end end end