From 3e40059f8d6cace0a2b8fa0c98e8f05bf13a3811 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Mon, 24 Apr 2017 08:49:11 +0100 Subject: utils: make which_editor handle editor args. Handle cases like e.g. `EDITOR="subl -w"`. --- Library/Homebrew/test/utils_spec.rb | 2 +- Library/Homebrew/utils.rb | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/test/utils_spec.rb b/Library/Homebrew/test/utils_spec.rb index 5f370a040..ffaa1f493 100644 --- a/Library/Homebrew/test/utils_spec.rb +++ b/Library/Homebrew/test/utils_spec.rb @@ -191,7 +191,7 @@ describe "globally-scoped helper methods" do ENV["HOMEBREW_EDITOR"] = "vemate" ENV["HOMEBREW_PATH"] = dir - editor = dir/"vemate" + editor = "#{dir}/vemate" FileUtils.touch editor FileUtils.chmod 0755, editor diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 82bc38895..5e0ad5916 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -321,7 +321,16 @@ end def which_editor editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL").compact.reject(&:empty?).first - return which(editor, ENV["HOMEBREW_PATH"]) unless editor.nil? + 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 = which("mate", ENV["HOMEBREW_PATH"]) @@ -338,7 +347,7 @@ def which_editor or HOMEBREW_EDITOR to your preferred text editor. EOS - editor + editor.to_s end def exec_editor(*args) -- cgit v1.2.3