aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAlex Dunn2017-03-07 10:36:57 -0800
committerAlex Dunn2017-03-19 16:32:23 -0700
commit00af5250f0a7988178ed8d26520bf1a98a8dea9a (patch)
tree0e7ba1f48c7889095d29c2eb6cf00807b2b9adfb /Library
parent76955b47bd2ae3eba1b041430d7e1aeab246de0d (diff)
downloadbrew-00af5250f0a7988178ed8d26520bf1a98a8dea9a.tar.bz2
caveats: combine completion and function messages
Fixes https://github.com/Homebrew/homebrew-core/issues/10338. Closes #2287. Signed-off-by: Alex Dunn <dunn.alex@gmail.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/caveats.rb79
-rw-r--r--Library/Homebrew/keg.rb27
2 files changed, 42 insertions, 64 deletions
diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb
index f5543cf49..61b703469 100644
--- a/Library/Homebrew/caveats.rb
+++ b/Library/Homebrew/caveats.rb
@@ -16,11 +16,9 @@ class Caveats
f.build = build
end
caveats << keg_only_text
- caveats << bash_completion_caveats
- caveats << zsh_completion_caveats
- caveats << fish_completion_caveats
- caveats << zsh_function_caveats
- caveats << fish_function_caveats
+ caveats << function_completion_caveats(:bash)
+ caveats << function_completion_caveats(:zsh)
+ caveats << function_completion_caveats(:fish)
caveats << plist_caveats
caveats << python_caveats
caveats << elisp_caveats
@@ -72,56 +70,35 @@ class Caveats
s << "\n"
end
- def bash_completion_caveats
+ def function_completion_caveats(shell)
return unless keg
- return unless keg.completion_installed?(:bash)
+ return unless which(shell.to_s)
- <<-EOS.undent
- Bash completion has been installed to:
- #{HOMEBREW_PREFIX}/etc/bash_completion.d
- EOS
- end
-
- def zsh_completion_caveats
- return unless keg
- return unless keg.completion_installed?(:zsh)
-
- <<-EOS.undent
- zsh completion has been installed to:
- #{HOMEBREW_PREFIX}/share/zsh/site-functions
- EOS
- end
-
- def fish_completion_caveats
- return unless keg
- return unless keg.completion_installed?(:fish)
- return unless which("fish")
+ completion_installed = keg.completion_installed?(shell)
+ functions_installed = keg.functions_installed?(shell)
+ return unless completion_installed || functions_installed
- <<-EOS.undent
- fish completion has been installed to:
- #{HOMEBREW_PREFIX}/share/fish/vendor_completions.d
- EOS
- end
+ installed = []
+ installed << "completions" if completion_installed
+ installed << "functions" if functions_installed
- def zsh_function_caveats
- return unless keg
- return unless keg.zsh_functions_installed?
-
- <<-EOS.undent
- zsh functions have been installed to:
- #{HOMEBREW_PREFIX}/share/zsh/site-functions
- EOS
- end
-
- def fish_function_caveats
- return unless keg
- return unless keg.fish_functions_installed?
- return unless which("fish")
-
- <<-EOS.undent
- fish functions have been installed to:
- #{HOMEBREW_PREFIX}/share/fish/vendor_functions.d
- EOS
+ case shell
+ when :bash
+ <<-EOS.undent
+ Bash completion has been installed to:
+ #{HOMEBREW_PREFIX}/etc/bash_completion.d
+ EOS
+ when :zsh
+ <<-EOS.undent
+ zsh #{installed.join(" and ")} have been installed to:
+ #{HOMEBREW_PREFIX}/share/zsh/site-functions
+ EOS
+ when :fish
+ fish_caveats = "fish #{installed.join(" and ")} have been installed to:"
+ fish_caveats << "\n #{HOMEBREW_PREFIX}/share/fish/vendor_completions.d" if completion_installed
+ fish_caveats << "\n #{HOMEBREW_PREFIX}/share/fish/vendor_functions.d" if functions_installed
+ fish_caveats
+ end
end
def python_caveats
diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 86733860c..cb9cd9113 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -302,23 +302,24 @@ class Keg
dir = case shell
when :bash then path.join("etc", "bash_completion.d")
when :zsh
- dir = path.join("share", "zsh", "site-functions")
- dir if dir && dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") }
- when :fish then path.join("share", "fish", "vendor_completions.d")
+ 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 && dir.directory? && !dir.children.empty?
end
- def zsh_functions_installed?
- # Check for non completion functions (i.e. files not started with an underscore),
- # since those can be checked separately
- dir = path.join("share", "zsh", "site-functions")
- dir && dir.directory? && dir.children.any? { |f| !f.basename.to_s.start_with?("_") }
- end
-
- def fish_functions_installed?
- dir = path.join("share", "fish", "vendor_functions.d")
- dir && dir.directory? && !dir.children.empty?
+ def functions_installed?(shell)
+ case shell
+ when :fish
+ dir = path/"share/fish/vendor_functions.d"
+ dir.directory? && !dir.children.empty?
+ when :zsh
+ # Check for non completion functions (i.e. files not started with an underscore),
+ # since those can be checked separately
+ dir = path/"share/zsh/site-functions"
+ dir.directory? && dir.children.any? { |f| !f.basename.to_s.start_with?("_") }
+ end
end
def plist_installed?