From 95688cd72e318fca1cb2a0652e48c5d4db5a1466 Mon Sep 17 00:00:00 2001 From: Zach Whaley Date: Thu, 8 Dec 2016 07:20:40 -0600 Subject: [PATCH 1/2] formula: Add convenience method for installing Zsh functions --- Library/Homebrew/formula.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 3f2653e4ab..bfaa41ad34 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -778,6 +778,14 @@ class Formula HOMEBREW_PREFIX+"var" end + # The directory where the formula's ZSH function files should be + # installed. + # This is symlinked into `HOMEBREW_PREFIX` after installation or with + # `brew link` for formulae that are not keg-only. + def zsh_function + share+"zsh/site-functions" + end + # The directory where the formula's fish function files should be # installed. # This is symlinked into `HOMEBREW_PREFIX` after installation or with From 14f46625a3e734a6b0e1ecdd8f146da20de5ea96 Mon Sep 17 00:00:00 2001 From: Zach Whaley Date: Sat, 3 Dec 2016 20:45:54 -0600 Subject: [PATCH 2/2] caveats: Differentiate zsh completion files and function files When installing a file to zsh/site-functions directory, it is assumed this is a zsh completion file, and the zsh completion caveat is printed after installation. But not all files in the zsh/site-functions directory are completion files. Some are files for functions that can be loaded on demand with zsh's autoload command. - Edit Keg.completion_installed to search specifically for files in the zsh/site-functions directory starting with an underscore only (By convention, zsh completion files start with an underscore) - Add Keg.zsh_functions_installed to search for non-completion files in the zsh/site-functions - Add Caveats.zsh_function_caveats to print a caveat if non-completion files have been installed to zsh/site-functions --- Library/Homebrew/caveats.rb | 11 +++++++++++ Library/Homebrew/keg.rb | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 0b1c0fd23a..3dfdb1c872 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -19,6 +19,7 @@ class Caveats caveats << bash_completion_caveats caveats << zsh_completion_caveats caveats << fish_completion_caveats + caveats << zsh_function_caveats caveats << fish_function_caveats caveats << plist_caveats caveats << python_caveats @@ -100,6 +101,16 @@ class Caveats EOS end + 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? diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index b3d88ea630..5c8e71d07e 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -297,12 +297,21 @@ class Keg def completion_installed?(shell) dir = case shell when :bash then path.join("etc", "bash_completion.d") - when :zsh then path.join("share", "zsh", "site-functions") + 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") 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?