| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'formula' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   def edit | 
					
						
							| 
									
										
										
										
											2012-08-02 10:20:06 -04:00
										 |  |  |     unless (HOMEBREW_REPOSITORY/'.git').directory? | 
					
						
							| 
									
										
										
										
											2012-08-01 15:56:52 -04:00
										 |  |  |       raise <<-EOS.undent
 | 
					
						
							|  |  |  |         Changes will be lost! | 
					
						
							|  |  |  |         The first time you `brew update', all local changes will be lost, you should
 | 
					
						
							|  |  |  |         thus `brew update' before you `brew edit'! | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-16 14:27:58 -08:00
										 |  |  |     # If no brews are listed, open the project root in an editor. | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     if ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2012-01-14 02:40:43 +00:00
										 |  |  |       editor = File.basename which_editor | 
					
						
							| 
									
										
										
										
											2012-09-10 12:28:00 -05:00
										 |  |  |       if editor == "mate" or editor == "subl" | 
					
						
							|  |  |  |         # If the user is using TextMate or Sublime Text, | 
					
						
							|  |  |  |         # give a nice project view instead. | 
					
						
							|  |  |  |         exec editor, HOMEBREW_REPOSITORY+"bin/brew", | 
					
						
							| 
									
										
										
										
											2011-12-16 14:27:58 -08:00
										 |  |  |                      HOMEBREW_REPOSITORY+'README.md', | 
					
						
							|  |  |  |                      HOMEBREW_REPOSITORY+".gitignore", | 
					
						
							|  |  |  |                     *library_folders | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         exec_editor HOMEBREW_REPOSITORY | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     else | 
					
						
							|  |  |  |       # Don't use ARGV.formulae as that will throw if the file doesn't parse | 
					
						
							|  |  |  |       paths = ARGV.named.map do |name| | 
					
						
							| 
									
										
										
										
											2012-03-05 16:02:46 +00:00
										 |  |  |         name = Formula.canonical_name name | 
					
						
							|  |  |  |         if name.include? '/' | 
					
						
							|  |  |  |           Pathname.new(name) | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           HOMEBREW_REPOSITORY+"Library/Formula/#{name}.rb" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |       unless ARGV.force? | 
					
						
							|  |  |  |         paths.each do |path| | 
					
						
							|  |  |  |           raise FormulaUnavailableError, path.basename('.rb').to_s unless path.file? | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       exec_editor *paths | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-08-24 14:45:01 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def library_folders | 
					
						
							|  |  |  |     Dir["#{HOMEBREW_REPOSITORY}/Library/*"].reject do |d| | 
					
						
							|  |  |  |       case File.basename(d) when 'LinkedKegs', 'Aliases' then true end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | end |