Enable 'brew edit' for non-Textmate editors.
This commit is contained in:
parent
df8edc94d6
commit
62e1dd8bd5
@ -98,7 +98,7 @@ For the full command list, see the COMMANDS section.
|
|||||||
if any problems are found.
|
if any problems are found.
|
||||||
|
|
||||||
* `edit`:
|
* `edit`:
|
||||||
Open all of Homebrew for editing in TextMate.
|
Open all of Homebrew for editing.
|
||||||
|
|
||||||
* `edit` <formula>:
|
* `edit` <formula>:
|
||||||
Open <formula> in $EDITOR.
|
Open <formula> in $EDITOR.
|
||||||
|
|||||||
@ -2,14 +2,18 @@ require 'formula'
|
|||||||
|
|
||||||
module Homebrew extend self
|
module Homebrew extend self
|
||||||
def edit
|
def edit
|
||||||
|
# If no brews are listed, open the project root in an editor.
|
||||||
if ARGV.named.empty?
|
if ARGV.named.empty?
|
||||||
# EDITOR isn't a good fit here, we need a GUI client that actually has
|
editor = which_editor
|
||||||
# a UI for projects, so apologies if this wasn't what you expected,
|
if editor == "mate"
|
||||||
# please improve it! :)
|
# If the user is using TextMate, give a nice project view instead.
|
||||||
exec 'mate', HOMEBREW_REPOSITORY+"bin/brew",
|
exec 'mate', HOMEBREW_REPOSITORY+"bin/brew",
|
||||||
HOMEBREW_REPOSITORY+'README.md',
|
HOMEBREW_REPOSITORY+'README.md',
|
||||||
HOMEBREW_REPOSITORY+".gitignore",
|
HOMEBREW_REPOSITORY+".gitignore",
|
||||||
*library_folders
|
*library_folders
|
||||||
|
else
|
||||||
|
exec_editor HOMEBREW_REPOSITORY
|
||||||
|
end
|
||||||
else
|
else
|
||||||
# Don't use ARGV.formulae as that will throw if the file doesn't parse
|
# Don't use ARGV.formulae as that will throw if the file doesn't parse
|
||||||
paths = ARGV.named.map do |name|
|
paths = ARGV.named.map do |name|
|
||||||
|
|||||||
@ -137,24 +137,26 @@ def puts_columns items, star_items=[]
|
|||||||
end
|
end
|
||||||
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
|
def exec_editor *args
|
||||||
return if args.to_s.empty?
|
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
|
# Invoke bash to evaluate env vars in $EDITOR
|
||||||
# This also gets us proper argument quoting.
|
# This also gets us proper argument quoting.
|
||||||
# See: https://github.com/mxcl/homebrew/issues/5123
|
# See: https://github.com/mxcl/homebrew/issues/5123
|
||||||
system "bash", "-c", editor + ' "$@"', "--", *args
|
system "bash", "-c", which_editor + ' "$@"', "--", *args
|
||||||
end
|
end
|
||||||
|
|
||||||
# GZips the given paths, and returns the gzipped paths
|
# GZips the given paths, and returns the gzipped paths
|
||||||
|
|||||||
@ -112,7 +112,7 @@ Check your system for potential problems\. Doctor exits with a non\-zero status
|
|||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fBedit\fR
|
\fBedit\fR
|
||||||
Open all of Homebrew for editing in TextMate\.
|
Open all of Homebrew for editing\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fBedit\fR \fIformula\fR
|
\fBedit\fR \fIformula\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user