Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't try to find the full path of the editor in 'brew edit' #2717

Merged
merged 1 commit into from Jun 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions Library/Homebrew/test/utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ def esc(code)
end

specify "#which_editor" do
ENV["HOMEBREW_EDITOR"] = "vemate"
ENV["HOMEBREW_EDITOR"] = "vemate -w"
ENV["HOMEBREW_PATH"] = dir

editor = "#{dir}/vemate"
FileUtils.touch editor
FileUtils.chmod 0755, editor

expect(which_editor).to eql editor
expect(which_editor).to eq("vemate -w")
end

specify "#gzip" do
Expand Down
32 changes: 15 additions & 17 deletions Library/Homebrew/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ def with_system_path
ENV["PATH"] = old_path
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)
old_locale = ENV["LC_ALL"]
ENV["LC_ALL"] = locale
Expand Down Expand Up @@ -321,23 +329,13 @@ def which_all(cmd, path = ENV["PATH"])

def which_editor
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
return editor unless editor.nil?

# Find Textmate, BBEdit / TextWrangler, or vim
%w[mate edit vim].each do |candidate|
editor = candidate if which(candidate, ENV["HOMEBREW_PATH"])
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
editor ||= "/usr/bin/vim"

Expand All @@ -347,12 +345,12 @@ def which_editor
or HOMEBREW_EDITOR to your preferred text editor.
EOS

editor.to_s
editor
end

def exec_editor(*args)
puts "Editing #{args.join "\n"}"
safe_exec(which_editor, *args)
with_homebrew_path { safe_exec(which_editor, *args) }
end

def exec_browser(*args)
Expand Down