Skip to content

Commit

Permalink
Merge pull request #9292 from MikeMcQuaid/improve-zsh-completions
Browse files Browse the repository at this point in the history
Improve ZSH completions handling
  • Loading branch information
MikeMcQuaid authored Nov 26, 2020
2 parents a6a77f2 + 3002c81 commit 86631b4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
31 changes: 26 additions & 5 deletions Library/Homebrew/caveats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ def caveats
f.build = build
end
caveats << keg_only_text
caveats << function_completion_caveats(:bash)
caveats << function_completion_caveats(:zsh)
caveats << function_completion_caveats(:fish)

valid_shells = [:bash, :zsh, :fish].freeze
current_shell = Utils::Shell.preferred || Utils::Shell.parent
shells = if current_shell.present? &&
(shell_sym = current_shell.to_sym) &&
valid_shells.include?(shell_sym)
[shell_sym]
else
valid_shells
end
shells.each do |shell|
caveats << function_completion_caveats(shell)
end

caveats << plist_caveats
caveats << elisp_caveats
caveats.compact.join("\n")
Expand Down Expand Up @@ -117,10 +128,20 @@ def function_completion_caveats(shell)
#{root_dir}/etc/bash_completion.d
EOS
when :zsh
<<~EOS
site_functions = root_dir/"share/zsh/site-functions"
zsh_caveats = +<<~EOS
zsh #{installed.join(" and ")} have been installed to:
#{root_dir}/share/zsh/site-functions
#{site_functions}
EOS
unless PATH.new(ENV["HOMEBREW_FPATH"]).to_a.include?(site_functions.to_s)
zsh_caveats << <<~EOS
#{site_functions} is not in your zsh FPATH!
Add it by following these steps:
#{Formatter.url("https://docs.brew.sh/Shell-Completion#configuring-completions-in-zsh")}
EOS
end
zsh_caveats.freeze
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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/caveats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def plist
before do
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(:preferred).and_return(nil)
allow(Utils::Shell).to receive(:parent).and_return(nil)
end

it "gives dir where bash completions have been installed" do
Expand Down
2 changes: 1 addition & 1 deletion bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ HOMEBREW_LIBRARY="$HOMEBREW_REPOSITORY/Library"

# Copy and export all HOMEBREW_* variables previously mentioned in
# manpage or used elsewhere by Homebrew.
for VAR in BROWSER DISPLAY EDITOR NO_COLOR PATH
for VAR in BROWSER DISPLAY EDITOR NO_COLOR PATH FPATH
do
# Skip if variable value is empty.
[[ -z "${!VAR}" ]] && continue
Expand Down

0 comments on commit 86631b4

Please sign in to comment.