@@ -262,6 +262,14 @@ def with_system_path
262262 ENV [ "PATH" ] = old_path
263263end
264264
265+ def with_homebrew_path
266+ old_path = ENV [ "PATH" ]
267+ ENV [ "PATH" ] = ENV [ "HOMEBREW_PATH" ]
268+ yield
269+ ensure
270+ ENV [ "PATH" ] = old_path
271+ end
272+
265273def with_custom_locale ( locale )
266274 old_locale = ENV [ "LC_ALL" ]
267275 ENV [ "LC_ALL" ] = locale
@@ -321,23 +329,13 @@ def which_all(cmd, path = ENV["PATH"])
321329
322330def which_editor
323331 editor = ENV . values_at ( "HOMEBREW_EDITOR" , "HOMEBREW_VISUAL" ) . compact . reject ( &:empty? ) . first
324- if editor
325- editor_name , _ , editor_args = editor . partition " "
326- editor_path = which ( editor_name , ENV [ "HOMEBREW_PATH" ] )
327- editor = if editor_args . to_s . empty?
328- editor_path . to_s
329- else
330- "#{ editor_path } #{ editor_args } "
331- end
332- return editor
332+ return editor unless editor . nil?
333+
334+ # Find Textmate, BBEdit / TextWrangler, or vim
335+ %w[ mate edit vim ] . each do |candidate |
336+ editor = candidate if which ( candidate , ENV [ "HOMEBREW_PATH" ] )
333337 end
334338
335- # Find Textmate
336- editor = which ( "mate" , ENV [ "HOMEBREW_PATH" ] )
337- # Find BBEdit / TextWrangler
338- editor ||= which ( "edit" , ENV [ "HOMEBREW_PATH" ] )
339- # Find vim
340- editor ||= which ( "vim" , ENV [ "HOMEBREW_PATH" ] )
341339 # Default to standard vim
342340 editor ||= "/usr/bin/vim"
343341
@@ -347,12 +345,12 @@ def which_editor
347345 or HOMEBREW_EDITOR to your preferred text editor.
348346 EOS
349347
350- editor . to_s
348+ editor
351349end
352350
353351def exec_editor ( *args )
354352 puts "Editing #{ args . join "\n " } "
355- safe_exec ( which_editor , *args )
353+ with_homebrew_path { safe_exec ( which_editor , *args ) }
356354end
357355
358356def exec_browser ( *args )
0 commit comments