Copied which_editor and exec_editor from brew utils to address #20074. … (#22338)

This commit is contained in:
abrammer 2016-06-25 07:34:51 -04:00 committed by Vítor Galvão
parent 0231138812
commit 745b7c283c
1 changed files with 25 additions and 5 deletions

View File

@ -97,12 +97,32 @@ module Hbc::Utils
return cmd_pn
end
# originally from Homebrew
def self.which_editor
editor = ENV.values_at("HOMEBREW_EDITOR", "VISUAL", "EDITOR").compact.first
return editor unless editor.nil?
# Find Textmate
editor = "mate" if which "mate"
# Find BBEdit / TextWrangler
editor ||= "edit" if which "edit"
# Find vim
editor ||= "vim" if which "vim"
# Default to standard vim
editor ||= "/usr/bin/vim"
opoo <<-EOS.undent
Using #{editor} because no editor was set in the environment.
This may change in the future, so we recommend setting EDITOR, VISUAL,
or HOMEBREW_EDITOR to your preferred text editor.
EOS
editor
end
# originally from Homebrew
def self.exec_editor(*args)
editor = [
*ENV.values_at('HOMEBREW_EDITOR', 'VISUAL', 'EDITOR'),
*%w{mate edit vim /usr/bin/vim}.map{ |x| which(x) }
].compact.first.to_s
exec(*editor.split.concat(args))
safe_exec(which_editor, *args)
end
# originally from Homebrew puts_columns