diff options
| -rw-r--r-- | Library/Contributions/manpages/brew.1.md | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cmd/edit.rb | 18 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 26 | ||||
| -rw-r--r-- | share/man/man1/brew.1 | 2 |
4 files changed, 27 insertions, 21 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 diff --git a/share/man/man1/brew.1 b/share/man/man1/brew.1 index 9df767f88..927870d46 100644 --- a/share/man/man1/brew.1 +++ b/share/man/man1/brew.1 @@ -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 |
