Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Use ENV[EDITOR] if possible
Browse files Browse the repository at this point in the history
Defaulting to EDITOR, then checking for the mate command, and then using
vim as a last resort.

Signed Off By: Max Howell <max@methylblue.com>

Plain brew edit still uses Textmate though because a client that
supported a project concept is required for that particular feature.
Patches for that welcome.
  • Loading branch information
scoates authored and mxcl committed Sep 5, 2009
1 parent 4d25f7b commit e23a612
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
12 changes: 12 additions & 0 deletions Library/Homebrew/utils.rb
Expand Up @@ -80,3 +80,15 @@ def puts_columns items, cols = 4
width=`stty size`.chomp.split(" ").last
IO.popen("pr -#{cols} -t", "w"){|io| io.write(items) }
end

def exec_editor *args
editor=ENV['EDITOR']
if editor.nil?
if system "which -s mate" and $?.success?
editor='mate'
else
editor='vim'
end
end
exec editor, *args
end
11 changes: 7 additions & 4 deletions bin/brew
Expand Up @@ -34,7 +34,7 @@ end
if Hardware.cpu_type == :ppc or Hardware.cpu_type == :dunno
abort "Sorry, Homebrew does not support your computer's CPU architecture."
end
unless system "which gcc-4.2 &> /dev/null" and $?.success?
unless system "which -s gcc-4.2" and $?.success?
abort "Sorry, Homebrew requires gcc 4.2, which is provided by Xcode 3.1"
end

Expand Down Expand Up @@ -66,11 +66,14 @@ begin

when 'edit'
if ARGV.named_empty?
exec "mate", *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
# 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', *Dir["#{HOMEBREW_PREFIX}/Library/*"]<<
"#{HOMEBREW_PREFIX}/bin/brew"<<
"#{HOMEBREW_PREFIX}/README"
else
exec "mate", *ARGV.formulae.collect {|f| f.path}
exec_editor *ARGV.formulae.collect {|f| f.path}
end

when 'install'
Expand Down Expand Up @@ -179,7 +182,7 @@ begin
if ARGV.include? '--macports'
exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}"
else
exec "mate", *ARGV.collect {|name| make name}
exec_editor *ARGV.collect {|name| make name}
end

when 'diy', 'configure'
Expand Down

5 comments on commit e23a612

@adamv
Copy link
Contributor

@adamv adamv commented on e23a612 Sep 7, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work if you have for instance:
EDITOR='mate -w'

@josh
Copy link
Contributor

@josh josh commented on e23a612 Sep 8, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hit the same issue as adam

@indirect
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

guys, tons of stuff breaks if your editor has args... this is why the mate command acts like "mate -w" if you symlink it to "mate_wait", and then set EDITOR=mate_wait

@adamv
Copy link
Contributor

@adamv adamv commented on e23a612 Sep 10, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I'm living in a non-command-line world if this is the first breakage I've noticed. Thanks for the symlink tip.

(It might help if "The Internet" wasn't recommending "mate -w" as the editor, I suppose.)

@mxcl
Copy link
Contributor

@mxcl mxcl commented on e23a612 Sep 10, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know that Andre, thanks. However I've got a patch in my queue which splits the EDITOR command by space anyway. Can anyone see this causing any problems? I gave it reasonable thought and went with "it'll be ok".

At least with the patch the apparently common usecase on mac of "mate -w" (I did this too until recently) will work.

Please sign in to comment.