Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ZSH completions handling #9292

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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