aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/dev-cmd/edit.rb
diff options
context:
space:
mode:
authorMike McQuaid2016-09-09 08:30:26 +0100
committerGitHub2016-09-09 08:30:26 +0100
commit930bcb7c52523a1e03a1de132192ad4cdd74ce7a (patch)
treec91de0dfb23f75507005deccbc1cd51458aad66d /Library/Homebrew/dev-cmd/edit.rb
parent1d66cdd3ade841c6b7cd8a71d4b71d5426d00a58 (diff)
parent027086d67386a58b06f3df92b9168dcb0319ef0e (diff)
downloadbrew-930bcb7c52523a1e03a1de132192ad4cdd74ce7a.tar.bz2
Merge pull request #881 from MikeMcQuaid/dev-cmd-sticky-homebrew-developer
Set HOMEBREW_DEVELOPER automatically
Diffstat (limited to 'Library/Homebrew/dev-cmd/edit.rb')
-rw-r--r--Library/Homebrew/dev-cmd/edit.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb
new file mode 100644
index 000000000..ef325b8b6
--- /dev/null
+++ b/Library/Homebrew/dev-cmd/edit.rb
@@ -0,0 +1,50 @@
+#: * `edit`:
+#: Open all of Homebrew for editing.
+#:
+#: * `edit` <formula>:
+#: Open <formula> in the editor.
+
+require "formula"
+
+module Homebrew
+ 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 editor == "mate" || editor == "subl"
+ # If the user is using TextMate or Sublime Text,
+ # give a nice project view instead.
+ 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)
+ unless path.file? || ARGV.force?
+ raise FormulaUnavailableError, name
+ end
+ path
+ end
+ exec_editor(*paths)
+ end
+ end
+
+ def library_folders
+ Dir["#{HOMEBREW_LIBRARY}/*"].reject do |d|
+ case File.basename(d) when "LinkedKegs", "Aliases" then true end
+ end
+ end
+end