Skip to content

Commit 3e40059

Browse files
committed
utils: make which_editor handle editor args.
Handle cases like e.g. `EDITOR="subl -w"`.
1 parent cfe2c3c commit 3e40059

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Library/Homebrew/test/utils_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def esc(code)
191191
ENV["HOMEBREW_EDITOR"] = "vemate"
192192
ENV["HOMEBREW_PATH"] = dir
193193

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

Library/Homebrew/utils.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,16 @@ def which_all(cmd, path = ENV["PATH"])
321321

322322
def which_editor
323323
editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL").compact.reject(&:empty?).first
324-
return which(editor, ENV["HOMEBREW_PATH"]) unless editor.nil?
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
333+
end
325334

326335
# Find Textmate
327336
editor = which("mate", ENV["HOMEBREW_PATH"])
@@ -338,7 +347,7 @@ def which_editor
338347
or HOMEBREW_EDITOR to your preferred text editor.
339348
EOS
340349

341-
editor
350+
editor.to_s
342351
end
343352

344353
def exec_editor(*args)

0 commit comments

Comments
 (0)