Skip to content

Commit de78999

Browse files
author
adrian
committed
don't try to find the full path of the editor in 'brew edit'
fixes #2709
1 parent 8b26dee commit de78999

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

Library/Homebrew/test/utils_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ def esc(code)
188188
end
189189

190190
specify "#which_editor" do
191-
ENV["HOMEBREW_EDITOR"] = "vemate"
191+
ENV["HOMEBREW_EDITOR"] = "vemate -w"
192192
ENV["HOMEBREW_PATH"] = dir
193193

194194
editor = "#{dir}/vemate"
195195
FileUtils.touch editor
196196
FileUtils.chmod 0755, editor
197197

198-
expect(which_editor).to eql editor
198+
expect(which_editor).to eq("vemate -w")
199199
end
200200

201201
specify "#gzip" do

Library/Homebrew/utils.rb

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ def with_system_path
262262
ENV["PATH"] = old_path
263263
end
264264

265+
def with_homebrew_path
266+
old_path = ENV["PATH"]
267+
ENV["PATH"] = ENV["HOMEBREW_PATH"]
268+
yield
269+
ensure
270+
ENV["PATH"] = old_path
271+
end
272+
265273
def with_custom_locale(locale)
266274
old_locale = ENV["LC_ALL"]
267275
ENV["LC_ALL"] = locale
@@ -321,23 +329,13 @@ def which_all(cmd, path = ENV["PATH"])
321329

322330
def which_editor
323331
editor = ENV.values_at("HOMEBREW_EDITOR", "HOMEBREW_VISUAL").compact.reject(&:empty?).first
324-
if editor
325-
editor_name, _, editor_args = editor.partition " "
326-
editor_path = which(editor_name, ENV["HOMEBREW_PATH"])
327-
editor = if editor_args.to_s.empty?
328-
editor_path.to_s
329-
else
330-
"#{editor_path} #{editor_args}"
331-
end
332-
return editor
332+
return editor unless editor.nil?
333+
334+
# Find Textmate, BBEdit / TextWrangler, or vim
335+
%w[mate edit vim].each do |candidate|
336+
editor = candidate if which(candidate, ENV["HOMEBREW_PATH"])
333337
end
334338

335-
# Find Textmate
336-
editor = which("mate", ENV["HOMEBREW_PATH"])
337-
# Find BBEdit / TextWrangler
338-
editor ||= which("edit", ENV["HOMEBREW_PATH"])
339-
# Find vim
340-
editor ||= which("vim", ENV["HOMEBREW_PATH"])
341339
# Default to standard vim
342340
editor ||= "/usr/bin/vim"
343341

@@ -347,12 +345,12 @@ def which_editor
347345
or HOMEBREW_EDITOR to your preferred text editor.
348346
EOS
349347

350-
editor.to_s
348+
editor
351349
end
352350

353351
def exec_editor(*args)
354352
puts "Editing #{args.join "\n"}"
355-
safe_exec(which_editor, *args)
353+
with_homebrew_path { safe_exec(which_editor, *args) }
356354
end
357355

358356
def exec_browser(*args)

0 commit comments

Comments
 (0)