diff options
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index c37633e41..cde2ee306 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -75,7 +75,7 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call backtrace = caller tap_message = nil caller_message = backtrace.detect do |line| - next unless line =~ %r{^#{Regexp.escape HOMEBREW_LIBRARY}/Taps/([^/]+/[^/]+)/} + next unless line =~ %r{^#{Regexp.escape(HOMEBREW_LIBRARY)}/Taps/([^/]+/[^/]+)/} tap = Tap.fetch $1 tap_message = "\nPlease report this to the #{tap} tap!" true @@ -175,7 +175,7 @@ module Homebrew end def system(cmd, *args) - puts "#{cmd} #{args*" "}" if ARGV.verbose? + puts "#{cmd} #{args * " "}" if ARGV.verbose? _system(cmd, *args) end @@ -262,6 +262,14 @@ ensure ENV["PATH"] = old_path end +def with_homebrew_path + old_path = ENV["PATH"] + ENV["PATH"] = ENV["HOMEBREW_PATH"] + yield +ensure + ENV["PATH"] = old_path +end + def with_custom_locale(locale) old_locale = ENV["LC_ALL"] ENV["LC_ALL"] = locale @@ -320,21 +328,17 @@ def which_all(cmd, path = ENV["PATH"]) end def which_editor - editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL").compact.reject(&:empty?).first - if editor - editor_name, _, editor_args = editor.partition " " - editor_path = which(editor_name, ENV["HOMEBREW_PATH"]) - editor = if editor_args.to_s.empty? - editor_path.to_s - else - "#{editor_path} #{editor_args}" - end - return editor + editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first + return editor unless editor.nil? + + # Find Textmate, BBEdit / TextWrangler, or vim + %w[mate edit vim].each do |candidate| + editor = candidate if which(candidate, ENV["HOMEBREW_PATH"]) end # Find Textmate editor = which("mate", ENV["HOMEBREW_PATH"]) - # Find BBEdit / TextWrangler + # Find BBEdit/TextWrangler editor ||= which("edit", ENV["HOMEBREW_PATH"]) # Find vim editor ||= which("vim", ENV["HOMEBREW_PATH"]) @@ -347,16 +351,16 @@ def which_editor or HOMEBREW_EDITOR to your preferred text editor. EOS - editor.to_s + editor end def exec_editor(*args) puts "Editing #{args.join "\n"}" - safe_exec(which_editor, *args) + with_homebrew_path { safe_exec(which_editor, *args) } end def exec_browser(*args) - browser = ENV["HOMEBREW_BROWSER"] || ENV["BROWSER"] + browser = ENV["HOMEBREW_BROWSER"] browser ||= OS::PATH_OPEN if defined?(OS::PATH_OPEN) return unless browser safe_exec(browser, *args) |
