diff options
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 46a8cc68e..28d7fc283 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -190,10 +190,10 @@ module Homebrew Gem::Specification.reset # Add Gem binary directory and (if missing) Ruby binary directory to PATH. - path = ENV["PATH"].split(File::PATH_SEPARATOR) - path.unshift(RUBY_BIN) if which("ruby") != RUBY_PATH - path.unshift(Gem.bindir) - ENV["PATH"] = path.join(File::PATH_SEPARATOR) + path = PATH.new(ENV["PATH"]) + path.prepend(RUBY_BIN) if which("ruby") != RUBY_PATH + path.prepend(Gem.bindir) + ENV["PATH"] = path if Gem::Specification.find_all_by_name(name, version).empty? ohai "Installing or updating '#{name}' gem" @@ -293,7 +293,7 @@ def quiet_system(cmd, *args) end def which(cmd, path = ENV["PATH"]) - path.split(File::PATH_SEPARATOR).each do |p| + PATH.new(path).each do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -307,7 +307,7 @@ def which(cmd, path = ENV["PATH"]) end def which_all(cmd, path = ENV["PATH"]) - path.to_s.split(File::PATH_SEPARATOR).map do |p| + PATH.new(path).map do |p| begin pcmd = File.expand_path(cmd, p) rescue ArgumentError @@ -320,25 +320,34 @@ def which_all(cmd, path = ENV["PATH"]) end def which_editor - editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL", "EDITOR").compact.first - return editor unless editor.nil? + editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_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 + end # Find Textmate - editor = "mate" if which "mate" + editor = which("mate", ENV["HOMEBREW_PATH"]) # Find BBEdit / TextWrangler - editor ||= "edit" if which "edit" + editor ||= which("edit", ENV["HOMEBREW_PATH"]) # Find vim - editor ||= "vim" if which "vim" + editor ||= which("vim", ENV["HOMEBREW_PATH"]) # Default to standard vim editor ||= "/usr/bin/vim" opoo <<-EOS.undent Using #{editor} because no editor was set in the environment. - This may change in the future, so we recommend setting EDITOR, VISUAL, + This may change in the future, so we recommend setting EDITOR, or HOMEBREW_EDITOR to your preferred text editor. EOS - editor + editor.to_s end def exec_editor(*args) @@ -347,7 +356,7 @@ def exec_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) @@ -406,8 +415,8 @@ def nostdout end end -def paths - @paths ||= ENV["PATH"].split(File::PATH_SEPARATOR).collect do |p| +def paths(env_path = ENV["PATH"]) + @paths ||= PATH.new(env_path).collect do |p| begin File.expand_path(p).chomp("/") rescue ArgumentError |
