Enable 'brew edit' for non-Textmate editors.

This commit is contained in:
Adam Vandenberg 2011-12-16 14:27:58 -08:00
parent df8edc94d6
commit 62e1dd8bd5
4 changed files with 27 additions and 21 deletions

View File

@ -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.

View File

@ -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|

View File

@ -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

View File

@ -112,7 +112,7 @@ Check your system for potential problems\. Doctor exits with a non\-zero status
.
.TP
\fBedit\fR
Open all of Homebrew for editing in TextMate\.
Open all of Homebrew for editing\.
.
.TP
\fBedit\fR \fIformula\fR