Merge pull request #2717 from orangea/brew-edit-fix

don't try to find the full path of the editor in 'brew edit'
This commit is contained in:
Mike McQuaid 2017-06-02 15:45:59 +01:00 committed by GitHub
commit 760f92abba
2 changed files with 17 additions and 19 deletions

View File

@ -188,14 +188,14 @@ describe "globally-scoped helper methods" do
end end
specify "#which_editor" do specify "#which_editor" do
ENV["HOMEBREW_EDITOR"] = "vemate" ENV["HOMEBREW_EDITOR"] = "vemate -w"
ENV["HOMEBREW_PATH"] = dir ENV["HOMEBREW_PATH"] = dir
editor = "#{dir}/vemate" editor = "#{dir}/vemate"
FileUtils.touch editor FileUtils.touch editor
FileUtils.chmod 0755, editor FileUtils.chmod 0755, editor
expect(which_editor).to eql editor expect(which_editor).to eq("vemate -w")
end end
specify "#gzip" do specify "#gzip" do

View File

@ -262,6 +262,14 @@ ensure
ENV["PATH"] = old_path ENV["PATH"] = old_path
end 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) def with_custom_locale(locale)
old_locale = ENV["LC_ALL"] old_locale = ENV["LC_ALL"]
ENV["LC_ALL"] = locale ENV["LC_ALL"] = locale
@ -321,23 +329,13 @@ end
def which_editor def which_editor
editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first
if editor return editor unless editor.nil?
editor_name, _, editor_args = editor.partition " "
editor_path = which(editor_name, ENV["HOMEBREW_PATH"]) # Find Textmate, BBEdit / TextWrangler, or vim
editor = if editor_args.to_s.empty? %w[mate edit vim].each do |candidate|
editor_path.to_s editor = candidate if which(candidate, ENV["HOMEBREW_PATH"])
else
"#{editor_path} #{editor_args}"
end
return editor
end end
# Find Textmate
editor = which("mate", ENV["HOMEBREW_PATH"])
# Find BBEdit / TextWrangler
editor ||= which("edit", ENV["HOMEBREW_PATH"])
# Find vim
editor ||= which("vim", ENV["HOMEBREW_PATH"])
# Default to standard vim # Default to standard vim
editor ||= "/usr/bin/vim" editor ||= "/usr/bin/vim"
@ -347,12 +345,12 @@ def which_editor
or HOMEBREW_EDITOR to your preferred text editor. or HOMEBREW_EDITOR to your preferred text editor.
EOS EOS
editor.to_s editor
end end
def exec_editor(*args) def exec_editor(*args)
puts "Editing #{args.join "\n"}" puts "Editing #{args.join "\n"}"
safe_exec(which_editor, *args) with_homebrew_path { safe_exec(which_editor, *args) }
end end
def exec_browser(*args) def exec_browser(*args)