55 lines
1.4 KiB
Ruby
Raw Normal View History

2016-04-08 16:28:43 +02:00
#: * `edit`:
#: Open all of Homebrew for editing.
#:
#: * `edit` <formula>:
#: Open <formula> in the editor.
require "formula"
module Homebrew
2016-09-26 01:44:51 +02:00
module_function
def edit
unless (HOMEBREW_REPOSITORY/".git").directory?
raise <<-EOS.undent
Changes will be lost!
The first time you `brew update', all local changes will be lost, you should
thus `brew update' before you `brew edit'!
EOS
end
# If no brews are listed, open the project root in an editor.
if ARGV.named.empty?
editor = File.basename which_editor
if ["atom", "subl", "mate"].include?(editor)
# If the user is using Atom, Sublime Text or TextMate
# give a nice project view instead.
2017-06-01 16:06:51 +02:00
exec_editor HOMEBREW_REPOSITORY/"bin/brew",
HOMEBREW_REPOSITORY/"README.md",
HOMEBREW_REPOSITORY/".gitignore",
*library_folders
else
exec_editor HOMEBREW_REPOSITORY
end
else
# Don't use ARGV.formulae as that will throw if the file doesn't parse
paths = ARGV.named.map do |name|
path = Formulary.path(name)
2016-09-23 11:01:40 +02:00
raise FormulaUnavailableError, name unless path.file? || ARGV.force?
path
end
2013-04-06 00:14:03 -05:00
exec_editor(*paths)
end
end
def library_folders
2013-10-30 13:20:48 -07:00
Dir["#{HOMEBREW_LIBRARY}/*"].reject do |d|
2016-09-11 17:41:51 +01:00
case File.basename(d)
when "LinkedKegs", "Aliases" then true
end
end
end
end