replace homebrew-fork method exec_editor
remove which_editor remove safe_exec
This commit is contained in:
parent
1792eb99f2
commit
774eae75a8
|
@ -17,6 +17,12 @@ class Hbc::CLI::Create < Hbc::CLI::Base
|
|||
exec_editor cask_path
|
||||
end
|
||||
|
||||
# for mocking
|
||||
# todo: add an :exec parameter to SystemCommand
|
||||
def self.exec_editor(*args)
|
||||
Hbc::Utils.exec_editor(*args)
|
||||
end
|
||||
|
||||
def self.template(cask_token)
|
||||
<<-EOS.undent
|
||||
cask :v1 => '#{cask_token}' do
|
||||
|
|
|
@ -12,6 +12,12 @@ class Hbc::CLI::Edit < Hbc::CLI::Base
|
|||
exec_editor cask_path
|
||||
end
|
||||
|
||||
# for mocking.
|
||||
# todo: add an :exec parameter to SystemCommand
|
||||
def self.exec_editor(*args)
|
||||
Hbc::Utils.exec_editor(*args)
|
||||
end
|
||||
|
||||
def self.help
|
||||
"edits the given Cask"
|
||||
end
|
||||
|
|
|
@ -132,6 +132,12 @@ module Hbc::Utils
|
|||
return cmd_pn
|
||||
end
|
||||
|
||||
def self.exec_editor(*args)
|
||||
editor = [ *ENV.values_at('HOMEBREW_EDITOR', 'VISUAL', 'EDITOR'),
|
||||
*%w{mate edit vim /usr/bin/vim} ].compact.first
|
||||
exec(editor, *args)
|
||||
end
|
||||
|
||||
# originally from Homebrew puts_columns
|
||||
def self.stringify_columns items, star_items=[]
|
||||
return if items.empty?
|
||||
|
|
|
@ -44,31 +44,6 @@ def curl *args
|
|||
safe_system curl, *args
|
||||
end
|
||||
|
||||
def which_editor
|
||||
editor = ENV.values_at('HOMEBREW_EDITOR', 'VISUAL', 'EDITOR').compact.first
|
||||
# If an editor wasn't set, try to pick a sane default
|
||||
return editor unless editor.nil?
|
||||
|
||||
# Find Textmate
|
||||
return 'mate' if Hbc::Utils.which "mate"
|
||||
# Find BBEdit / TextWrangler
|
||||
return 'edit' if Hbc::Utils.which "edit"
|
||||
# Find vim
|
||||
return 'vim' if Hbc::Utils.which "vim"
|
||||
# Default to standard vim
|
||||
return '/usr/bin/vim'
|
||||
end
|
||||
|
||||
def exec_editor *args
|
||||
safe_exec(which_editor, *args)
|
||||
end
|
||||
|
||||
def safe_exec cmd, *args
|
||||
# This buys us proper argument quoting and evaluation
|
||||
# of environment variables in the cmd parameter.
|
||||
exec "/bin/sh", "-c", "#{cmd} \"$@\"", "--", *args
|
||||
end
|
||||
|
||||
def ignore_interrupts(opt = nil)
|
||||
std_trap = trap("INT") do
|
||||
puts "One sec, just cleaning up" unless opt == :quietly
|
||||
|
|
Loading…
Reference in New Issue