aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorAdam Vandenberg2011-12-16 14:27:58 -0800
committerAdam Vandenberg2011-12-16 14:27:58 -0800
commit2b297bc03f1ba8faf3af9b1cb96d2371d99d2a3c (patch)
tree291ccaa8614641d643e51a3f2450af3d4973e9c5 /Library
parent76ec8e18cfadf81c53a4239c76b1443867cde63e (diff)
downloadhomebrew-2b297bc03f1ba8faf3af9b1cb96d2371d99d2a3c.tar.bz2
Enable 'brew edit' for non-Textmate editors.
Diffstat (limited to 'Library')
-rw-r--r--Library/Contributions/manpages/brew.1.md2
-rw-r--r--Library/Homebrew/cmd/edit.rb18
-rw-r--r--Library/Homebrew/utils.rb26
3 files changed, 26 insertions, 20 deletions
diff --git a/Library/Contributions/manpages/brew.1.md b/Library/Contributions/manpages/brew.1.md
index cddf08435..96a1ce3f3 100644
--- a/Library/Contributions/manpages/brew.1.md
+++ b/Library/Contributions/manpages/brew.1.md
@@ -98,7 +98,7 @@ For the full command list, see the COMMANDS section.
if any problems are found.
* `edit`:
- Open all of Homebrew for editing in TextMate.
+ Open all of Homebrew for editing.
* `edit` <formula>:
Open <formula> in $EDITOR.
diff --git a/Library/Homebrew/cmd/edit.rb b/Library/Homebrew/cmd/edit.rb
index 252892caa..a2f5082b5 100644
--- a/Library/Homebrew/cmd/edit.rb
+++ b/Library/Homebrew/cmd/edit.rb
@@ -2,14 +2,18 @@ require 'formula'
module Homebrew extend self
def edit
+ # If no brews are listed, open the project root in an editor.
if ARGV.named.empty?
- # EDITOR isn't a good fit here, we need a GUI client that actually has
- # a UI for projects, so apologies if this wasn't what you expected,
- # please improve it! :)
- exec 'mate', HOMEBREW_REPOSITORY+"bin/brew",
- HOMEBREW_REPOSITORY+'README.md',
- HOMEBREW_REPOSITORY+".gitignore",
- *library_folders
+ editor = which_editor
+ if editor == "mate"
+ # If the user is using TextMate, give a nice project view instead.
+ exec 'mate', 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|
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 6d4d8c237..adf9c8d10 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -137,24 +137,26 @@ def puts_columns items, star_items=[]
end
end
+def which_editor
+ editor = ENV['HOMEBREW_EDITOR'] || ENV['EDITOR']
+ # If an editor wasn't set, try to pick a sane default
+ return editor unless editor.nil?
+
+ # Find Textmate
+ return 'mate' if system "/usr/bin/which -s mate"
+ # Find # BBEdit / TextWrangler
+ return 'edit' if system "/usr/bin/which -s edit"
+ # Default to vim
+ return '/usr/bin/vim'
+end
+
def exec_editor *args
return if args.to_s.empty?
- editor = ENV['HOMEBREW_EDITOR'] || ENV['EDITOR']
- if editor.nil?
- editor = if system "/usr/bin/which -s mate"
- 'mate'
- elsif system "/usr/bin/which -s edit"
- 'edit' # BBEdit / TextWrangler
- else
- '/usr/bin/vim' # Default to vim
- end
- end
-
# Invoke bash to evaluate env vars in $EDITOR
# This also gets us proper argument quoting.
# See: https://github.com/mxcl/homebrew/issues/5123
- system "bash", "-c", editor + ' "$@"', "--", *args
+ system "bash", "-c", which_editor + ' "$@"', "--", *args
end
# GZips the given paths, and returns the gzipped paths